简体   繁体   English

带有多个引号的sed词

[英]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. 我已经花了3个小时的时间来解决这个问题,但是我不是Linux技术人员,但是这很烦人。

I need to find a piece of text in a file test.txt 我需要在文件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. 您能帮我一下,告诉我正确的sed命令看起来如何。

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 请参见基本正则表达式语法概述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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