In my project in .sh
file I wrote this command:
var1=`sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g;s/^/"/g;s/$/"/g' ${var}`
sed -i "s/%PQR%/$var1/g" file2
Here var
is the variable which stores location of the file that I want to update. I want double quotes to be added at the start and end of file. Also I want all the new lines to be replaced with \n
.
example:
To err is to human.
This is life.
output:
"To err is to human.\nThis is life."
Then I want %PQR%
in file2
to be replaced with var1
.
But on running pipeline, the get the error on the second command as described in the title:
sed: -e expression#1 char 48: unterminated `s' command
I guess you could try each sed expression individually, to see if they all work.
– Alexander Oct 05 '21 at 09:51$var1
after setting it? Prefix the secondsed
command withecho
. Does what you see look like a validsed
command? – Chris Davies Oct 05 '21 at 09:54sed
is, since there's an unterminated command substitution there, so even those shell commands won't run won't run. You might want to use e.g. shellcheck.net to check the syntax. Then, you show one error message, but don't tell which sed command gives it. Reduce the problem by removing the parts that are not a problem, and then show a complete, working, but minimal piece of code that shows the problem, along with any values you use. Or even enableset -x
and show the output too, so we can see what actually runs. – ilkkachu Oct 05 '21 at 10:47