LukeJ LukeJ -4 years ago 34
Linux Question

sed words with several quotation marks

I spent already 3 hrs of my time trying to solve this but I'm not Linux tech but this is so annoying.

I need to find a piece of text in a file test.txt

"cPHulk":{"BruteForce":3,"Login":3,"*":3}


and change it for:

"cPHulk":{"BruteForce":1,"Login":1,"*":1}


Could you please help me and tell me how would the correct sed command looks like.

Many thanks for your help

EDIT: I've tried this:

sed -e "s/\"cPHulk\":{\"BruteForce\":3,\"Login\":3,\"*\":3}/\"cPHulk\":{\"BruteForce\":1,\"Login\":1,\"*\":1}" /root/test.txt


But unfortunately I'm getting error:

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

Answer Source
$ cat ip.txt 
foo
"cPHulk":{"BruteForce":3,"Login":3,"*":3}
bar

$ sed 's/"cPHulk":{"BruteForce":3,"Login":3,"\*":3}/"cPHulk":{"BruteForce":1,"Login":1,"*":1}/' ip.txt 
foo
"cPHulk":{"BruteForce":1,"Login":1,"*":1}
bar

Use single quotes, only * needs to be escaped. See Overview of basic regular expression syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download