Unix 打印匹配行后的所有行

Unix 打印匹配行后的所有行,unix,sed,awk,Unix,Sed,Awk,如何打印第n行中匹配模式后的所有行,而忽略匹配行(包括匹配行)前的所有行,下面是一个示例: row1 something in this row row2 something in this row row3 something in this row row4 don't need to match the whole line, something like java String.contains() row5 something in this row row6 something in

如何打印第n行中匹配模式后的所有行,而忽略匹配行(包括匹配行)前的所有行,下面是一个示例:

row1 something in this row
row2 something in this row
row3 something in this row
row4 don't need to match the whole line, something like java String.contains()
row5 something in this row
row6 something in this row
row7 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
我希望在包含第4行的行之后打印该行中的任何位置,这是否可以使用awk或sed,或者任何其他方式

输出应为:

row5 something in this row
row6 something in this row
row7 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
我见过类似的问题:


但我不知道如何调整它以满足我的需要。

您可以使用以下命令:

grep -A 5 "row4" test.txt
输出将是:

row4
row5
row6
row7
row8
row9

-A
表示After,类似地,您可以使用表示Before的
-B
5
是要输出的行数。当然,您可以选择您想要的任何内容。

您可以使用以下命令:

grep -A 5 "row4" test.txt
输出将是:

row4
row5
row6
row7
row8
row9

-A
表示After,类似地,您可以使用表示Before的
-B
5
是要输出的行数。当然,你可以选择你想要的任何东西。

这是可行的,一位大师可能会大大缩短它:

#!/usr/bin/perl
$pat = shift(@ARGV);
$p = 0;
while(<>) {
  if ($p == 1) { print $_;}
  if ($_ =~ /$pat/) {
    $p = 1;
  }
}

这是可行的,一位大师可能会大大缩短它:

#!/usr/bin/perl
$pat = shift(@ARGV);
$p = 0;
while(<>) {
  if ($p == 1) { print $_;}
  if ($_ =~ /$pat/) {
    $p = 1;
  }
}

如果Perl可以使用,您可以执行以下操作:

perl -ne 'print if($f); $f=1 if(/row4/)'

如果Perl可以使用,您可以执行以下操作:

perl -ne 'print if($f); $f=1 if(/row4/)'
试试这个:

sed '1,/row4/d' inputfile
试试这个:

sed '1,/row4/d' inputfile