Как найти шаблон $ iperf в файле, используя perl - PullRequest
0 голосов
/ 30 июня 2009

Как мне найти и отобразить слово $ iperf в файле

Файл будет выглядеть так

$iperf -c 172.29.38.67 -m -M 64 -i 5 -t 20 -P 10
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
------------------------------------------------------------

~ $ iperf -c 172.29.38.67 -m -M 128 -i 5 -t 20 -P 10
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
------------------------------------------------------------
Client connecting to 172.29.38.67, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------

1 Ответ

1 голос
/ 30 июня 2009

Похоже, вам нужно регулярное выражение. Строка '$iperf' не существует в ваших данных, поэтому я предполагаю, что вы имеете в виду 'iperf'. Вы можете найти строки, содержащие эту строку, зацикливая файл по одной строке за раз и проверяя каждую строку регулярным выражением Если регулярное выражение выполнено успешно, вы можете напечатать строку.

#!/usr/bin/perl

use strict;
use warnings;

while (<DATA>) {
    print if /\biperf\b/;
}

__DATA__
$iperf -c 172.29.38.67 -m -M 64 -i 5 -t 20 -P 10
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
WARNING: attempt to set TCP maximum segment size to 64, but got 536
------------------------------------------------------------

~ $ iperf -c 172.29.38.67 -m -M 128 -i 5 -t 20 -P 10
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
WARNING: attempt to set TCP maximum segment size to 128, but got 536
------------------------------------------------------------
Client connecting to 172.29.38.67, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...