- 论坛徽章:
- 16
|
回复 5# yinyuemi
回复 30# blackold - Three things to note about address ranges: the syntax is addr1,addr2 (i.e., the addresses are separated by a
- comma); the line which addr1 matched will always be accepted, even if addr2 selects an earlier line; and if addr2 is a regexp, it will
- not be tested against the line that addr1 matched.
复制代码 挖坟回答一下,看官方手册有3个说明暗示,其中第二个是addr1一直会被接受,这样理解就合理了,第二个-e的时候,-e '1,2d' 虽然是第三行,address1是1,但always be accepted ,even if addr2 selects an earlier line.
此外下边还有一个
If the second address is a number less than (or equal to) the line matching the first address, then only the one line is matched。
跟上述的Note 2是相吻合的。
所以该行会被处理,删了3. 这个是最合理的解释了。
此外补充一下0,/regexp/这种,基本上等价于1,/regexp/只有当第一行匹配/regexp/的时候,二者做法不同- echo 'abc
- 2
- 3
- 4
- 5
- xyz'|sed -n '0,/abc/p'
- abc
复制代码 结束,只打印第一行匹配的结果,而1,/regexp/会正常展开,
- echo 'abc
- 2
- 3
- 4
- 5'|sed -n '1,/abc/p'
- abc
- 2
- 3
- 4
- 5
复制代码 此时符合我回复过的情况,从addr1开始搜,一直找到addr2为止(直到文本处理完毕)
此帖可以关闭了. |
|