sed, negate and variable
Hey!
I'm trying to use sed to search through a text, and replace a variable containing spaces with 'bar'. But i don't want to replace on lines containing 'foo'. The reason i want to use a variable is that the sed-command is in a for-loop, so it get's a different variable each loop. It works when i want to replace on lines with foo: Code:
$ echo ${test} Code:
$ sed "/foo/!s/${test// /\\ }/bar/g" file Code:
$ sed '/foo/!s/test1\ test2/bar/g' file Otherwise i get: Code:
$ sed '/foo/s/${test// /\\ }/bar/g' file Or can i use sed-branching to test if the regexp foo is not on a line? Or does anyone have a good hint on how to achieve this? Thanks! |
Quote:
You need the sed command in single quotes. You can fragment it so parts that need shell expansion are in double quotes. sed '/foo/!s/'"${test// /\\ }"'/bar/g' file |
Ok, it works! I thought i had tried every possible combination of backticks, double/single quotes. Apperently not :D
Thanks heaps jschiwal! |
All times are GMT -5. The time now is 11:51 AM. |