Find and replace / editing text in a config file

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Bloomfield 3 months, 2 weeks ago.

  • Author
  • #92651


    First off this is my first post. Very new to powershell
    I am attempting to edit a oracle config file

    Path \\server name\c$\MW\MW\user_projects\domains\db name\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_11.1.2\config\default.env.

    I wish to replace the default line:



    I have tried the following which fails:

    (get-content "C:\path\default.env") | foreach-object {$_ -replace "FORMS_PATH=C:\MW\MW\Oracle_FRHome1\forms;C:\MW\MW\asinst_1\FormsComponent\forms", "FORMS_PATH=C:\path;FORMS_NMAP=False;FORMS_TIMEOUT=10;NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252"} | set-content "C:\path\default.env"

  • #92714

    Matt Bloomfield

    Hi. Please let us know what errors you get when posting requests for help otherwise we have to guess at the problem.

    My guess is that you're getting an invalid regex error message?

    I don't know the structure of the file you're replacing the content in but I've been lazy and not matched the whole string explicitly. I've told it to just replace any string that starts with FORMS and ends with a bunch of other stuff. We can get a bit more specific with the regex if that's going to be a problem (i.e. if more than one line in the file starts with FORMS).

    This should do what you need:

    (Get-Content E:\temp\env.txt) -replace "^FORMS.*","FORMS_PATH=C:\path`r`nFORMS_NMAP=False`r`nFORMS_TIMEOUT=10`r`nNLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252" | Set-Content E:\temp\env.txt

    Note the use of `r`n to insert the carriage returns.

You must be logged in to reply to this topic.