简体   繁体   中英

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
$ 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM