I am trying to substitute a line in my existing file with the set of lines from another file. Regarding the existing file, i am sure that the line i am substituting will occur only at one place.
I have stored the text to be replaced in another file.
First off sorry to the OP.I do not intend to hijack this thread but I only have a similar problemSo thought of asking it here than opening a new thread.
I have the following in a sh script called var
#!/bin/bash
var1=0
And on another script called main I use a if construct:
#!/bin/bash
. var
if [ "$var1" == "0"]
Do this
else
do that
fi
Now in do this part,I have to change the value of var1 from "0" to "1".Any help is much appreciated :).Thanks and once again sorry to OP.
Regards,
vijai
Seems to work here, and I'm pretty sure those are standard sed commands.
$ cat InputFile.txt
before
Parameters "CParameters"
after
$ cat TextToReplace.txt
aaa
bbb
$ sed -e '/Parameters "CParameters"/r TextToReplace.txt' -e "//d" InputFile.txt
before
aaa
bbb
after
$ sed -e '/CParameters/r TextToReplace.txt' -e "//d" InputFile.txt
before
aaa
bbb
after
You don't need to \ escape the "CParameters" double quotes, because inside the single quotes. I avoid those confusing \ characters if possible.
Any chance there is a tab character in the pattern? Maybe there is something about the pattern that is "funny" and is confusing us. You might try to find the pattern with grep first, to figure out the regular expression. Another option is to experiment with the final version above with simple pattern, verify that works, then move on to the longer pattern.
Great. The way you are using sed is ideal. sed is so powerful for just this kind of discrete task. And it's kind of fun.
A lot of the power and challenge of sed is getting as good as possible at regular expressions. You can do a lot with a short script and a well-written regular expression, as in the case of the script you are using.