I created a test text document. I then wrote a short test script. I first ran the grep command with color highlighting to verify the searched text existed (two places). I ran one instance of sed with single marks and the next line with double. I did not perform inline replacement and only I displayed the results on screen.
Double quotation marks works with variables. Single quotation marks do not.
I next modified the script to perform the replacement inline.
Same result.
Huh.
Go figure. Another lesson learned in the book called life.
I suppose I have to learn why double marks work and single do not. Probably has something to do with how bash parses, escapes, and interprets everything.
I also learned that the first variable must contain back slashes to escape certain characters but the replacement variable does not. Perhaps whatever I was trying recently I did not properly use back slashes.
Seems to work and thanks!
Next, back to my original problem: how to use sed to traverse multiple lines? That is, replace something with nothing. I found a
mini how-to that explained this syntax:
sed "/$VAR1/,/$VAR2/d" ~/test.txt
I defined $VAR1 as the first line I wanted to delete. I defined $VAR2 as the last line I wanted to deleted. Worked great but because the document contained empty line breaks to separate paragraphs, I was left with a double blank line.
I then found the following example to delete double blank lines:
sed "/./,/^$/!d"
I then tried the following:
sed "/$VAR1/,/$VAR2/d" ~/test.txt | sed "/./,/^$/!d"
That worked great but the output was to stdout not actual inline replacement. I next tried:
sed "/$VAR1/,/$VAR2/d" ~/test.txt | sed "/./,/^$/!d" > ~/test2.txt
cat ~/test2.txt
Worked great again. Next I tried:
sed -i "/$VAR1/,/$VAR2/d" ~/test.txt | sed -i "/./,/^$/!d" ~/test.txt
cat ~/test.txt
And that seems to be the successful end of this particular sed lesson for me.
I still think KFileReplace has much potential and is sadly neglected. Yet I hope this thread helps somebody else!
Thanks.