Kolya
29th December 2006 17:54 UTC
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.
Red Wine
29th December 2006 18:31 UTC
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
Kolya
29th December 2006 19:28 UTC
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.
Kolya
17th September 2007 19:08 UTC
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.
Kolya
25th September 2007 17:24 UTC
Is the answer so obvious that the question isn't deemed worthy of one? :igor:
kichik
25th September 2007 20:14 UTC
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.