V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
qq674949301
V2EX  ›  问与答

使用 sed 来修改一个配置文件问题求教

  •  
  •   qq674949301 · Aug 24, 2015 · 2105 views
    This topic created in 3912 days ago, the information mentioned may be changed or developed.
    某路径下这个配置文件:
    #!/bin/sh

    ENABLED=yes
    PROCS=chinadns
    ARGS="-b 127.0.0.1 -p 5353 -c /opt/etc/chnroute.txt -s 114.114.114.114,208.67.222.222:443,8.8.8.8:53"
    PREARGS=""
    DESC=$PROCS
    PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    . /opt/etc/init.d/rc.func

    我想修改 114.114.114.114 为本地的 DNS ,还有我已经指定这个$DNS 为本地的 DNS ,我该如何用 sed 命令修改:
    EP:
    #!/bin/sh

    DNS=`sed -n '1p' /jffs/dns.list`

    sed ........

    sed 请问各位这部分该如何实现?
    3 replies    2015-08-26 09:12:16 +08:00
    neilp
        1
    neilp  
       Aug 24, 2015
    sed -i 's/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\15.5.5.5\2/' a.txt
    neilp
        2
    neilp  
       Aug 24, 2015
    用这个:

    sed "s/^ARGS=\(.*\)114.114.114.114\(.*\)$/ARGS=\1$DNS\2/" a.txt
    qq674949301
        3
    qq674949301  
    OP
       Aug 26, 2015
    @neilp thanks
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   954 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 19:10 · PVG 03:10 · LAX 12:10 · JFK 15:10
    ♥ Do have faith in what you're doing.