Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grep表示字符串(如果包含在多个连续行中)_Grep - Fatal编程技术网

Grep表示字符串(如果包含在多个连续行中)

Grep表示字符串(如果包含在多个连续行中),grep,Grep,我有一个日志文件,我想在其中查找包含特定字符串的行,如果它至少包含五个连续的行 例如,我的日志文件如下所示: Sent RTP packet to 10.124.193.26:12486 (type 09, seq 030081, ts 2726949472, len 000160) Got RTP packet from 10.124.193.26:12486 (type 09, seq 052435, ts 174852800, len 000160) Sent RTP p

我有一个日志文件,我想在其中查找包含特定字符串的行,如果它至少包含五个连续的行

例如,我的日志文件如下所示:

Sent RTP packet to      10.124.193.26:12486 (type 09, seq 030081, ts 2726949472, len 000160)
Got  RTP packet from    10.124.193.26:12486 (type 09, seq 052435, ts 174852800, len 000160)
Sent RTP packet to      10.124.193.26:12486 (type 09, seq 030082, ts 2726949632, len 000160)
Got  RTP packet from    10.124.193.26:12486 (type 09, seq 052436, ts 174852960, len 000160)
Sent RTP packet to      10.124.193.26:12486 (type 09, seq 030083, ts 2726949792, len 000160)
Got  RTP packet from    10.124.193.26:12486 (type 09, seq 052437, ts 174853120, len 000160)
Sent RTP packet to      10.124.193.26:12486 (type 09, seq 030084, ts 2726949952, len 000160)
Got  RTP packet from    10.124.193.26:12486 (type 09, seq 052438, ts 174853280, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055416, ts 87947536, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055417, ts 87947696, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055418, ts 87947856, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055419, ts 87948016, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055420, ts 87948176, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055421, ts 87948336, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055422, ts 87948496, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055423, ts 87948656, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055424, ts 87948816, len 000160)
Sent RTP packet to      10.124.193.90:11836 (type 09, seq 055425, ts 87948976, len 000160)
第一行以“Sent”或“Got”交替开头。 这些很好,我对它们不感兴趣。 然后是仅以“Sent”开头的连续行。 我想找的那些。
如何使用grep或其他命令查找它们?

您可以使用以下命令:

$ cat <filename> | awk '{ if( pre == "Sent" && $1 == "Sent" ) {print $0} ; {pre=$1} }'
$cat | awk'{if(pre==“Sent”&&$1==“Sent”){print$0};{pre=$1}
说明:


记住最后一行的第一个单词。如果是“已发送”,并且如果当前行的第一个字也是“已发送”,则打印当前行

多谢各位。当两个连续的行以“Sent”开头时打印。我只需要在连续5行以“Sent”开头时打印。可能的