这个问题来源于ChinaUnix的一篇帖子“sed地址和模式匹配的问题”。
man sed手册说明
Sed默认的命令执行范围是全局的,如果想仅对其中部分行执行命令,可以使用地址限制。在Manual手册中有一节关于地址的描述,摘取部分如下:
Sed commands can be given with no addresses, in which case the command will be executed for all input lines;
Sed默认是全局编辑的,因此如果不明确指定行的话,命令会在所有输入行上执行。
with one address, in which case the command will only be executed for input lines which match that address;
如果指定一个行地址,那么sed命令就限制在那一行执行。
or with two addresses, in which case the command will be executed for all input lines which match the inclusive range of lines starting from the first address and continuing to the second address.
如果给了两个地址,即地址对(或者地址范围),则命令在匹配的这个地址范围内执行。但是需要注意的几点是:
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; If addr2 is a regexp, it will not be tested against the line that addr1 matched.
继续阅读