How can I find and display the word $iperf in a file
The file will look like this
$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)
------------------------------------------------------------
It sounds like you need a regex. The string '$iperf'
does not exist in your data, so I am going to assume you mean 'iperf'
. You can find the lines that contain that string by looping over the file one line at a time and testing each line with a regex. If the regex succeeds, then you can print the line.
#!/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)
------------------------------------------------------------
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.