我编写了以下awk来从匹配行打印行直到EOF
awk '/match_line/,/*/' file
我怎样才能在sed中做同样的事情?
答案 0 :(得分:49)
sed -n '/matched/,$p' file
awk '/matched/,0' file
答案 1 :(得分:15)
这适用于Windows上非常旧版的GNU sed
GNU sed版本2.05
http://www.gnu.org/software/sed/manual/sed.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
匹配行
后打印everthing>sed.exe -n -e "1,/needle/!p" haystack.txt
want 1
want 2