我写了下面的awk来打印从匹配行到EOF的行数。
awk '/match_line/,/*/' file
如何在 sed 中做同样的事情?
sed -n '/matched/,$p' file
awk '/matched/,0' file
这是在Windows上使用的GNU sed的老版本。
GNU sed 2.05版
http:/www.gnu.orgsoftwaresedmanualsed.html
-n only display if Printed
-e expression to evaluate
p stands for Print
$ end of file
line1,line2 is the range
! is NOT
abc
def
ghi
needle
want 1
want 2
将匹配的行和下面的行打印到文件末尾。
>sed.exe -n -e "/needle/,$p" haystack.txt
needle
want 1
want 2
打印文件的起始行,直到但不包括匹配行。
>sed.exe -n -e "/needle/,$!p" haystack.txt
abc
def
ghi
打印文件的开始部分,包括匹配的行。
>sed.exe -n -e "1,/needle/p" haystack.txt
abc
def
ghi
needle
打印匹配行后的所有内容
>sed.exe -n -e "1,/needle/!p" haystack.txt
want 1
want 2
打印两场比赛之间的所有内容--包括
>sed.exe -n -e "/def/,/want 1/p" haystack.txt
def
ghi
needle
want 1