免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: mr_caoke
打印 上一主题 下一主题

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

论坛徽章:
1
天秤座
日期:2013-10-23 13:20:42
1 [报告]
发表于 2010-04-12 14:31 |显示全部楼层
[monitor@test ~]$ sed '2p' ./tmp.sed
The honeysuckle band played all night long for only $90.
It was an evening of splendid music and company.
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.

[monitor@test ~]$ sed -n '2p' ./tmp.sed
It was an evening of splendid music and company.

[monitor@test ~]$ sed -n '/It/p' ./tmp.sed   
It was an evening of splendid music and company.

[monitor@test ~]$ sed -n '/It/,2p' ./tmp.sed
It was an evening of splendid music and company.

[monitor@test ~]$ sed -n '/It/,2'p ./tmp.sed  
It was an evening of splendid music and company.

[monitor@test ~]$ sed -n '/It/,3p' ./tmp.sed  
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.

[monitor@test ~]$ sed -n '/an/p' ./tmp.sed     
The honeysuckle band played all night long for only $90.
It was an evening of splendid music and company.
The local nurse Miss P.Neave was in attendance.

[monitor@test ~]$ sed -n '/an/2p' ./tmp.sed  
sed: -e expression #1, char 5: unknown command: `2'

[monitor@test ~]$ sed -n '/an/,2p' ./tmp.sed
The honeysuckle band played all night long for only $90.
It was an evening of splendid music and company.
The local nurse Miss P.Neave was in attendance.

应该很清楚了,那就是个label

论坛徽章:
1
天秤座
日期:2013-10-23 13:20:42
2 [报告]
发表于 2010-04-14 17:04 |显示全部楼层
回复  mr_caoke


    早就解释清楚了。


   add1, add2地址对(范围),基本的就不说了。

我再重 ...
blackold 发表于 2010-04-12 17:19


黑哥,对于
我再重复一下。
   /an/,2p  第1行匹配/an/,地址范围为真,执行p;
第2行,匹配2, 地址范围为真, 执行p, 之后地址范围为假(重置)

这段有点不通看法,
既然是/an/,2p,   /an/是个匹配字段,那/an/ 找的行<=2时,sed 就自动将/an/到2行的内容全部p出来。
而到到/an/匹配而 >2行时,就只p出这一行了
不知我的看法是否正确。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP