I'm currently getting this output from iperf3
2016-03-03 21:33:50 [ 4] 0.00-1.00 sec 113 MBytes 950 Mbits/sec
2016-03-03 21:33:50 [ 4] 1.00-2.00 sec 112 MBytes 941 Mbits/sec 0
2016-03-03 21:33:50 [ 4] 2.00-3.00 sec 113 MBytes 944 Mbits/sec 0
I want to create Graphics from this data, and as iperf3 can't update timestamps by line (as far as I know..) I'm looking for a way to increment the output file line by line.
result should be like:
2016-03-03 21:33:50 [ 4] 0.00-1.00 sec 113 MBytes 950 Mbits/sec
2016-03-03 21:33:51 [ 4] 1.00-2.00 sec 112 MBytes 941 Mbits/sec 0
2016-03-03 21:33:52 [ 4] 2.00-3.00 sec 113 MBytes 944 Mbits/sec 0
so an action (+1) has to be done on each line containing Mbits/sec until the end of the file.
I guess that sed and/or date command may be helpful and a loop may be useful but can't see how to build it with time values..
awk '$10=="Mbits/sec"\
{command="date -d "$2" +%s";command |getline $2;close(command)};1' 1txt \
| awk -vi=1 '$10=="Mbits/sec"{$2=$2+i};i=i+1'\
| awk '$10=="Mbits/sec"{command="date -d @"$2" +%T";command|getline $2;close(command)};1'
tested it on a file 1txt having values:
2016-03-03 21:33:50 [ 4] 0.00-1.00 sec 113 MBytes 950 Mbits/sec
2016-03-03 21:33:50 [ 4] 1.00-2.00 sec 112 MBytes 941 Mbits/sec 0
2016-03-03 21:33:50 [ 4] 2.00-3.00 sec 113 MBytes 944 Mbits/sec 0
2016-03-03 21:33:50 [ 4] 2.00-3.00 sec 113 MBytes 944 bits/sec 0
the output as expected after execution was:
2016-03-03 21:33:51 [ 4] 0.00-1.00 sec 113 MBytes 950 Mbits/sec
2016-03-03 21:33:52 [ 4] 1.00-2.00 sec 112 MBytes 941 Mbits/sec 0
2016-03-03 21:33:53 [ 4] 2.00-3.00 sec 113 MBytes 944 Mbits/sec 0
2016-03-03 21:33:50 [ 4] 2.00-3.00 sec 113 MBytes 944 bits/sec 0
P.S: you can ofcourse make it more compact and efficient by combining the awk's in a single command. But this helps in better understanding of whats going on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With