- 论坛徽章:
- 0
|
本帖最后由 mpstat 于 2011-09-08 11:11 编辑
回复 15# xinglu1983
first~step
This GNU extension matches every stepth line starting with line first. In particular, lines will be selected when there exists a non-negative n such that the current line-number equals first + (n * step). Thus, to select the odd-numbered lines, one would use 1~2; to pick every third line starting with the second, ‘2~3’ would be used; to pick every fifth line starting with the tenth, use ‘10~5’; and ‘50~0’ is just an obscure way of saying 50.
GNU sed also supports some special two-address forms; all these are GNU extensions:
0,/regexp/
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.
Note that this is the only place where the 0 address makes sense; there is no 0-th line and commands which are given the 0 address in any other way will give an error.
addr1,+N
Matches addr1 and the N lines following addr1.
addr1,~N
Matches addr1 and the lines following addr1 until the next line whose input line number is a multiple of N.
网上找了点中文版的:
-------------- PS -1:GNU extension Collection:--------------------
1. GNU 恰巧有许多对 POSIX sed 标准便利、省时的扩展。另外,GNU 没有 sed 早期专门版本的很多限制,如行长度限制 -- GNU 可以轻松处理任意长度的行.
2. first~step GNU扩展,选定 起始行~步长 的那些行。例如选择所有奇数行1~2;选择从第2行开始的,每隔3行 ‘2~3' ; 选择从第10行开始的每隔5行.
3. /regexp/I 和 \%regexp%I : GNU扩展,忽略大小写.
4. 0,/regexp/ : 这是唯一一个使用0作为行号不会报错的用法,一般情况下不存在”第0行”,在任何其他命令中使用0作地址都会报错.
5. addr1,+N 匹配addr1和它后边的N行
6. addr1,~N 匹配addr1和它后边的行,直到输入的下一行的行号是N的倍数 |
|