且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SED:在匹配前寻址两行

更新时间:2023-12-03 18:28:40

这可能对你有用(GNU sed):

This might work for you (GNU sed):

sed -n ':a;$!{N;s/\n/&/2;Ta};/^PATTERN\'\''/MP;$!D' file

这将打印整个文件中 PATTERN 之前的第 2 行.

This will print the line 2 lines before the PATTERN throughout the file.