【发布时间】:2011-03-26 22:56:04
【问题描述】:
我编写了以下 awk 来打印从匹配行到 EOF 的行
awk '/match_line/,/*/' file
如何在 sed 中做同样的事情?
【问题讨论】:
标签: sed
我编写了以下 awk 来打印从匹配行到 EOF 的行
awk '/match_line/,/*/' file
如何在 sed 中做同样的事情?
【问题讨论】:
标签: sed
这是针对 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
打印文件开头直到 AND 包括匹配行
>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
【讨论】:
# show global/file attributes of some compressed netCDF files 987654330 FN='emis_mole_all_2008*' 987654332 echo -e "Processing ${GZ}, start=$(date)" 987654334 NETCDF_FN="${GZ_FN%.gz}" 987654336 gunzip ./${GZ_FN} 987654338 echo # newline between files 987654340 @
sed -n '/matched/,$p' file
awk '/matched/,0' file
【讨论】:
$是指文件的结尾,而不是行的结尾吗?
$ 在 sed 中表示 end of file