I want to prefix the line containing the string echo ‘"xxx.yyy" with "# " (ash+space) string in file.txt using sed in linux
output should look like this: # echo ‘"xxx.yyy"
I tried this:
find file.txt -type f -exec sed -i ‘s|"echo ‘"xxx.yyy""|"# echo ‘"xxx.yyy""|g’ {} ;
But i am getting the error: sed: -e expression #1, char 23: unterminated `s’ command
Should i escape any character here?
What am I doing wrong here?
2
Answers
Your single quotes in the search and replacement are causing the error that the
s
option is unterminated assed
does not see the complete command.To fix it, you can try this
sed
I will show the
sed
commands without-i
. Add-i
when it works like you want.When you are not sure how much quotes you have, you can try
or when you are already happy when a line has both
echo
andxxx.yyy
:In both commands, the
&
stands for the part that is matched.