2016-01-29 58 views
0

我需要提取的iperf日誌文件輸出的最高值忽略行的第一項7.提取從最高值的iperf結果

------------------------------------------------------------ 
Client connecting to 10.10.10.2, TCP port 5001 
TCP window size: 0.02 MByte (default) 
------------------------------------------------------------ 
[ 3] local 10.10.10.1 port 44809 connected with 10.10.10.2 port 5001 
[ ID] Interval  Transfer  Bandwidth 
[ 3] 0.0- 1.0 sec 2.50 MBytes 21.0 Mbits/sec 
[ 3] 1.0- 2.0 sec 2.25 MBytes 18.9 Mbits/sec 
[ 3] 2.0- 3.0 sec 2.00 MBytes 16.8 Mbits/sec 
[ 3] 3.0- 4.0 sec 2.25 MBytes 18.9 Mbits/sec 
[ 3] 4.0- 5.0 sec 2.00 MBytes 16.8 Mbits/sec 
[ 3] 5.0- 6.0 sec 2.25 MBytes 18.9 Mbits/sec 
[ 3] 6.0- 7.0 sec 2.12 MBytes 17.8 Mbits/sec 
[ 3] 7.0- 8.0 sec 2.00 MBytes 16.8 Mbits/sec 
[ 3] 8.0- 9.0 sec 2.25 MBytes 18.9 Mbits/sec 
[ 3] 9.0-10.0 sec 2.00 MBytes 16.8 Mbits/sec 
[ 3] 0.0-10.1 sec 21.8 MBytes 18.0 Mbits/sec 

到目前爲止,我有

#!/bin/bash 
iperf -c 10.0.0.2 -t 10 -f m -i 1 > /tmp/max.log 
sed -i '7d' /tmp/max.log 

我現在需要以回顯結果列中的最高值18.9

回答

3

您可以在沒有sed的情況下執行操作,並讓awk忽略第7行中的所有內容。

$ awk 'NR > 7 { max = $(NF-1) > max ? $(NF-1) : max } END { print max }' m.txt 
18.9