【发布时间】:2018-04-19 14:20:14
【问题描述】:
我有一个日志文件,我想在其中查找包含特定字符串的行,如果它至少有五个连续的行包含它。
例如我的日志文件如下所示:
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”交替开头。 这些都很好,我对它们不感兴趣。 然后是仅以“已发送”开头的连续行。 那些我想找到的。 如何使用 grep 或其他命令找到它们?
【问题讨论】:
标签: grep