免费注册 查看新帖 |

Chinaunix

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

问一个有关sed匹配模式的话题 [复制链接]

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
发表于 2010-04-12 15:17 |显示全部楼层
刚才测试了,我上面说的是有错误。

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
发表于 2010-04-12 15:20 |显示全部楼层
回复 10# mr_caoke


    这是地址范围。add1,add2

   当add2是行号NUMBER,且NUMBER小于add1,那么只匹配一行。

论坛徽章:
0
发表于 2010-04-12 15:21 |显示全部楼层
回复 7# mr_caoke


    第三行中有attendance单词包含an。
   在这个模式中前面已经有了出现了一个/an/直到第二行的范围
   sed继续在读入第三行后继续匹配模式,匹配到an,又开始一次范围的匹配

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
发表于 2010-04-12 15:35 |显示全部楼层
9楼解释的很清楚

论坛徽章:
0
发表于 2010-04-12 15:47 |显示全部楼层
回复 13# ghp268


    我来分析一下吧

文件中含有如下行

The honeysuckle band played all night long for only $90.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.
The local nurse Miss P.Neave was in attendance.

sed -n '/an/,2'p  tmp.sed

第一行有 band ,所以匹配

第二行有 an,所以匹配

第三行既没有an,也不是第2行,所以没匹配。

第四行有attendance,所以匹配

是这样的过程吗?

如果是,那这个应该解释成an或者2,随便匹配哪个都可以

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
发表于 2010-04-12 15:51 |显示全部楼层
回复 15# mr_caoke


    LZ强!

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
发表于 2010-04-12 15:55 |显示全部楼层
回复 15# mr_caoke


看看你的理解能否解释这个:
# cat urfile
The honeysuckle band played all night long for only $90.
Hello world.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.
The local nurse Miss P.Neave was in attendance.

# sed -n '/an/,3'p urfile
The honeysuckle band played all night long for only $90.
Hello world.
It was an evening of splendid music and company.
The local nurse Miss P.Neave was in attendance.

论坛徽章:
0
发表于 2010-04-12 15:58 |显示全部楼层
回复 15# mr_caoke


    addr1,addr2是一个地址范围,标示了起止。你觉得addr1在一个地址范围中需要匹配两次么

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
发表于 2010-04-12 15:59 |显示全部楼层
回复 17# Shell_HAT


    应该是DOS的原因,看界面就知道了。这个解释应该八九不离十了。

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
发表于 2010-04-12 16:12 |显示全部楼层
回复 19# blackold


这个不是DOS问题吧,黑哥,我认为9楼正解:
# cat urfile
The honeysuckle band played all night long for only $90.
Hello world.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.
The local nurse Miss P.Neave was in attendance.

# sed -n '/an/,3'p urfile
The honeysuckle band played all night long for only $90.
Hello world.
It was an evening of splendid music and company.
The local nurse Miss P.Neave was in attendance.

# uname -a
Linux ubuntu 2.6.24-22-generic #1 SMP Mon Nov 24 19:35:06 UTC 2008 x86_64 GNU/Linux
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP