Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
gouera
V2EX  ›  Linux

关于sed的用法。

  •  
  •   gouera · Oct 19, 2013 · 4108 views
    This topic created in 4598 days ago, the information mentioned may be changed or developed.
    [root@localhost ~]# sed '/aa/,10/d' a.txt
    sed: -e expression #1, char 8: unknown command: `/'


    删除从含有aa的行到第10行, 不是这样写么,怎么会报错。
    如果把10后面的d去掉,效果又不是一样的了。
    求帮忙啊。
    7 replies    1970-01-01 08:00:00 +08:00
    h2ero
        1
    h2ero  
       Oct 19, 2013
    sed '/aa/,10d' a.txt
    gouera
        2
    gouera  
    OP
       Oct 19, 2013
    [root@localhost ~]# wc -l a.txt
    33 a.txt
    [root@localhost ~]# sed '/aa/,10d' a.txt
    [root@localhost ~]#


    @h2ero 貌似不对啊。 这个文件有33行。 删了10行还有23啊。。 怎么没输出了。
    kemad
        3
    kemad  
       Oct 19, 2013
    man sed

    addr1,+N
    Will match addr1 and the N lines following addr1.
    rrfeng
        4
    rrfeng  
       Oct 19, 2013
    [rr@mypc ~]#seq 10|sed '/3/,5d'
    1
    2
    6
    7
    8
    9
    10
    [rr@mypc ~]#^
    rrfeng
        5
    rrfeng  
       Oct 19, 2013
    你是要删除 /aa/ 后的10行

    还是 /aa/ 到 第 10 行
    gouera
        6
    gouera  
    OP
       Nov 30, 2013
    @rrfeng 删除1-10行里面含有/aa/的行啊。
    rrfeng
        7
    rrfeng  
       Nov 30, 2013
    @gouera

    1,10{/aa/d}
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   912 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 20:59 · PVG 04:59 · LAX 13:59 · JFK 16:59
    ♥ Do have faith in what you're doing.