sed 替换两个符号之间的内容为别的内容怎么写

2016-02-19 23:50:17 +08:00
 fazero

{
"port_password":{
"2016":"helloss",
"1027":"wwwcc"
},
"method":"aes-256-cfb",
"timeout":600
}
要把第三行中的 helloss 替换成 haha 可以下面这样
sed -i 's/helloss/haha/g' filename
但是 helloss 是不确定的,我只是想把第三行第二对双引号之间的内容替换成 haha ,应该怎么写啊

1896 次点击
所在节点    正则表达式
4 条回复
rrfeng
2016-02-20 00:00:04 +08:00
人生苦短,请用 json 解析库……
Strikeactor
2016-02-20 00:02:17 +08:00
sed 's/"2016":".*"/"2016":"haha"/'
fazero
2016-02-20 00:10:43 +08:00
@Strikeactor 谢谢,太强了
SoloCompany
2016-02-20 02:25:23 +08:00
echo ‘
{
"port_password":{
"2016":"hello\"ss",
"1027":"wwwcc"
},
"method":"aes-256-cfb",
"timeout":600
}' | node -e '
x=JSON.parse(require("fs").readFileSync("/dev/stdin"))
x.port_password["2016"] = "f*ckgfw?"
console.log(JSON.stringify(x))

{"port_password":{"1027":"wwwcc","2016":"f*ckgfw?"},"method":"aes-256-cfb","timeout":600}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/257775

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX