fazero

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

  •  
  •   fazero · Feb 19, 2016 · 2563 views
    This topic created in 3748 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
        1
    rrfeng  
       Feb 20, 2016
    人生苦短,请用 json 解析库……
    Strikeactor
        2
    Strikeactor  
       Feb 20, 2016   ❤️ 1
    sed 's/"2016":".*"/"2016":"haha"/'
    fazero
        3
    fazero  
    OP
       Feb 20, 2016
    @Strikeactor 谢谢,太强了
    SoloCompany
        4
    SoloCompany  
       Feb 20, 2016
    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   ·   Solana   ·   959 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 1124ms · UTC 19:44 · PVG 03:44 · LAX 12:44 · JFK 15:44
    ♥ Do have faith in what you're doing.