免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: swysn

用sed如何删除2至10行与aaa匹配的行? [复制链接]

论坛徽章:
0
发表于 2003-02-21 15:49 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

...

原帖由 "laoxia" 发表:

谢英雄指正,改一下

sed -n '1p' filename; sed -n '2,10p' filename | sed '/aaa/d' ; sed -n '10,$p' filename


laoxia 喜欢衣服反着穿,呵呵。


  1. sed '2,10 {
  2. /aaa/d
  3. }' filename
复制代码


就可以了

论坛徽章:
0
发表于 2003-02-21 16:39 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

原帖由 "红袖添香" 发表:

就可以了


佩服!!!!!!!!!!!!!!!!

论坛徽章:
0
发表于 2003-02-21 16:47 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

红袖添香
不能实现阿

论坛徽章:
0
发表于 2003-02-21 16:56 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

原帖由 "swysn" 发表:
红袖添香
不能实现阿


不应该吧,我在OpenBSD下测试过的。

你是什么系统?也许 sed 版本不一样?

论坛徽章:
0
发表于 2003-02-21 17:10 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

原帖由 "红袖添香"][quote:d5eec14ee5="swysn" 发表:
红袖添香
不能实现阿


不应该吧,我在OpenBSD下测试过的。

你是什么系统?也许 sed 版本不一样?[/quote]

      ...
      ters in the file are `#n', the default output is suppressed.
      This is the same as specifying the -n option on the command line.

   The sed utility exits 0 on success or >0 if an error occurred.

SEE ALSO
   awk(1), ed(1), grep(1), regex(3), re_format(7)

STANDARDS
   The sed function is expected to be a superset of the IEEE Std1003.2
   (``POSIX.2'') specification.

HISTORY
   A sed command appeared in Version 7 AT&T UNIX.

OpenBSD 3.1          December 30, 1993              5


我的 man page 上说是 POSIX.2 标准的,不是特殊的呀~  >_<

论坛徽章:
0
发表于 2003-02-21 21:23 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

我试过好多次输出的是原来的内容,奇怪!
scounix5.0.5

论坛徽章:
0
发表于 2003-02-21 22:13 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

...


我又在 Solaris 和 IRIX 下试过了。都通过了。是不是你想达到的目的跟我们理解的不一样?

在 Solaris, IRIX, OpenBSD 下运行的结果:

原文件 filename:  

     1  aaa
     2  asdfasdf
     3  111
     4  aaa
     5  aaa
     6  ddddadfa
     7  asdfadsf
     8
     9  asdfasdf
    10
    11  dfdj
    12  afdfasdffad
    13  ad
    14  ddddfadf
    15  d
    16  adfasdfads
    17  asdfad
    18  adfad
    19  aaa
    20  adf

运行后  

     1  aaa
     2  asdfasdf
     3  111
     6  ddddadfa
     7  asdfadsf
     8
     9  asdfasdf
    10
    11  dfdj
    12  afdfasdffad
    13  ad
    14  ddddfadf
    15  d
    16  adfasdfads
    17  asdfad
    18  adfad
    19  aaa
    20  adf

其中 2-10 行中含有 aaa 的行,4,5 被删除了,其它则保留。1,10-20 都无影响。

论坛徽章:
0
发表于 2003-02-22 00:27 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

是那样啊
奇怪,我运行了后输出的与原来的内容是一样的

论坛徽章:
0
发表于 2003-02-22 15:30 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

狂晕!!!
重新启动后就可以了!
另:
为什么要大括号?中,小怎么不行?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2003-02-22 23:51 |显示全部楼层

用sed如何删除2至10行与aaa匹配的行?

机器昨晚没喂
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP