vaclavambroz
vaclavambroz

Reputation: 35

Bash: special characters in sed

I want to replace with sed in some bash script something like:

s:44:\"STRING\"

To:

s:NEWSTRING:\"NEWSTRING2\"

I tried many ways with escaping special characters, but I got always error

sed: -e expression #1, char 32: unterminateds' command`

or someting like that.

Can you please tell me the correct sed -i (sed -i "s/xxx/xxx/g" file) command for that?

Upvotes: 0

Views: 144

Answers (2)

PesaThe
PesaThe

Reputation: 7499

You have to escape the backslashes properly:

sed 's/s:44:\\"STRING\\"/s:NEWSTRING:\\"NEWSTRING2\\"/'

Example:

$ echo 's:44:\"STRING\"' | sed 's/s:44:\\"STRING\\"/s:NEWSTRING:\\"NEWSTRING2\\"/g'
s:NEWSTRING:\"NEWSTRING2\"

Upvotes: 1

Frank Förster
Frank Förster

Reputation: 371

You are missing the final delimiter. In your case it seems to be : therefore, you need to add a final : after your substitution content. It does not matter if you are using modification instruction like g

Upvotes: 0

Related Questions