sed 匹配模式问题

http://bbs.chinaunix.net/thread-3557086-1-2.html

 CU论坛上面的题目上面链接地址。

昨天没搞懂主要是在看那个info sed 中上面那么一点点英文

然后刚刚有点懂了

jk@ck ~/spt> seq 6|sed -e '1,2d' -e '1,4d' 
5
6

这个是我电脑上面的结果。我简单解释下,那个论坛上面已经解释的很清楚 了


第一次是把1,2 行删除,然后剩下3 4 5 6行,此时行号没有改变。

然后开始第二次的匹配第二次是从第一行删除的,但是第一行刚刚已经被删除了。现在的行号是3

但是在sed的说明书上面有那么一段就是这么说的.就是五楼贴的那个。

A line number of 0 can be used in an address specification like 0,/regexp/ so that sed will try to match regexp in the first input line too. In other words, 0,/regexp/ is similar to 1,/regexp/, except that if addr2 matches the very first line of input the 0,/regexp/ form will consider it to end the range,

看下面这一句。

 whereas the 1,/regexp/ form will match the beginning of its range and hence make the range span up to the second occurrence of the regular expression.

      最后一句就是说第一行肯定会匹配,不管要匹配的那个行号。

我个人认为是这样的。

如果有什么不对的地方请在下面留言。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值