fazero

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

  •  
  •   fazero · Feb 19, 2016 · 2981 views
    This topic created in 3920 days ago, the information mentioned may be changed or developed.

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

    4 replies  •  2016-02-20 02:25:23 +08:00
    rrfeng
    rrfeng
    Feb 20, 2016
    1
    人生苦短,请用 json 解析库……
    Strikeactor
    Strikeactor
    Feb 20, 2016❤️1
    2
    sed 's/"2016":".*"/"2016":"haha"/'
    fazero
    fazero
    OP
    Feb 20, 2016
    3
    @Strikeactor 谢谢,太强了
    SoloCompany
    SoloCompany
    Feb 20, 2016
    4
    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}
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2115 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:17 · PVG 09:17 · LAX 17:17 · JFK 20:17
    ♥ Do have faith in what you're doing.