Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed error: unterminated 's' command

Tags:

unix

sed

I run below sed command

sed -i s/abc=.*$/abc=def ghi/g hpq_sf_attach_wf_param.txt

and it gave me error:

sed: -e expression #1, char 17: unterminated `s' command

I noticed it is due to space in between of def and ghi. Any idea how to fix it?

like image 818
iwan Avatar asked Apr 25 '12 02:04

iwan


People also ask

What does S in sed mean?

In some versions of sed, the expression must be preceded by -e to indicate that an expression follows. The s stands for substitute, while the g stands for global, which means that all matching occurrences in the line would be replaced.

How do you use sed S?

Find and replace text within a file using sed command Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace. It tells sed to find all occurrences of 'old-text' and replace with 'new-text' in a file named input.txt.

What does sed '/ $/ D do?

env | sed '/^#/ d' | sed '/^$/ d' Concatenate FILE(s), or standard input, to standard output. With no FILE, or when FILE is -, read standard input.

How do you escape a backslash in sed?

Use single quotes for sed and you can get away with two backslashes. echo "sample_input\whatever" | sed 's/\\/\//' Hopefully someone will come up with the correct explanation for this behavior.


1 Answers

You need to use quoting to protect special characters, including spaces, $, and *.

sed -i 's/abc=.*$/abc=def ghi/g' hpq_sf_attach_wf_param.txt
like image 164
geekosaur Avatar answered Sep 19 '22 16:09

geekosaur