
{
"port_password":{
"2016":"helloss",
"1027":"wwwcc"
},
"method":"aes-256-cfb",
"timeout":600
}
要把第三行中的 helloss 替换成 haha 可以下面这样
sed -i 's/helloss/haha/g' filename
但是 helloss 是不确定的,我只是想把第三行第二对双引号之间的内容替换成 haha ,应该怎么写啊
1 rrfeng 2016-02-20 00:00:04 +08:00 人生苦短,请用 json 解析库…… |
2 Strikeactor 2016-02-20 00:02:17 +08:00 sed 's/"2016":".*"/"2016":"haha"/' |
3 fazero OP @Strikeactor 谢谢,太强了 |
4 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} |