Sed Error: Unterminated 'S' Command

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?

2

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
2

So geekosaur had it right. The the reason you had the problem though is because it needs to be double quotes for the wildcards because with single quotes it takes them as literal characters, not for the meaning you want.

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

Also if the space between "def" and "ghi" gives you problems, adding a "\" should help making it read it as a literal space.

sed -i "s/abc=.*$/abc=def\ ghi/g" hpq_sf_attach_wf_param.txt
2
Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest