Archive: config file editing with external editor


config file editing with external editor
I want to use an external file editor (sed) to make some changes to config files.
In this example I want to add a line to the end of the file. The command is:

sed.exe -e "$ a\last line" <oldfile>newfile


For NSIS I changed it to:
ExecWait "sed.exe -e $\"$$ a\last line$\" <oldfile>newfile"


As you can see I escaped the inner quotes since single quotes don't work. I also escaped the $-sign. Apparently that didn't help.

I don't know what's special about this sed thing, in NSIS you may simply use FileWrite, e.g.

FileOpen $R0 "path_to_file\file.ext" a
FileSeek $R0 0 END
FileWrite $R0 "text_to_write_here"
FileClose $R0


Thank you, this worked great.
The reason I want to use sed is that I need to do search&replace edits incl. regular expression searching.


The reason I want to use sed is that I need to do search&replace edits incl. regular expression searching.
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.5

http://nsis.sourceforge.net/Docs/AppendixE.html#E.2

http://nsis.sourceforge.net/Docs/AppendixE.html#E.3

Okay, it's been a while...I still have a question. :)

The links you posted didn't really help me, as they all seem to refer to cases where the search string is completely known.
Here's the problem: I have a config.cfg file that contains a string:

resources_base c:\programs\blah\+d:\cd\


Now a user could have installed the program anywhere (or changed the path manually) and the only part that stays the same is the "resources_base" part. But I need to change the installation path of course, which is unknown.

EDIT: So what I need is something like this:
SearchAndReplace config.cfg "resources_base *" "resources_base newstring"

A wildcard. A joker. Nowhere in the docs could I find that.

Is the answer so obvious that the question isn't deemed worthy of one? :igor:


You can do that with LineFind. It'll pass your function the configuration line by line. You can then copy the first 15 characters of the string and compare those to "resources_base ". If you find that line, tell LineFind to replace it with your own.