V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
gouera
V2EX  ›  Linux

关于sed的用法。

  •  
  •   gouera · 2013-10-19 10:43:14 +08:00 · 3412 次点击
    这是一个创建于 3848 天前的主题,其中的信息可能已经有所发展或是发生改变。
    [root@localhost ~]# sed '/aa/,10/d' a.txt
    sed: -e expression #1, char 8: unknown command: `/'


    删除从含有aa的行到第10行, 不是这样写么,怎么会报错。
    如果把10后面的d去掉,效果又不是一样的了。
    求帮忙啊。
    7 条回复    1970-01-01 08:00:00 +08:00
    h2ero
        1
    h2ero  
       2013-10-19 11:03:44 +08:00
    sed '/aa/,10d' a.txt
    gouera
        2
    gouera  
    OP
       2013-10-19 11:38:17 +08:00
    [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  
       2013-10-19 17:53:54 +08:00
    man sed

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

    还是 /aa/ 到 第 10 行
    gouera
        6
    gouera  
    OP
       2013-11-30 16:13:16 +08:00
    @rrfeng 删除1-10行里面含有/aa/的行啊。
    rrfeng
        7
    rrfeng  
       2013-11-30 17:36:34 +08:00
    @gouera

    1,10{/aa/d}
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2195 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:05 · PVG 08:05 · LAX 17:05 · JFK 20:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.