3

Getting the error:

(standard_in) 1: syntax error

When running the below script:

#!/bin/bash
while read line
do time=$(echo $line|awk '{print $10}'|awk -F"=" '{print $2}')
if (( $(echo "$time > 100" | bc -l) ))
then echo $line
fi
done  < ping.txt

The ping.txt file contains lines like below:

2018-08-15 13:45:54: 64 bytes from server.my.local (192.168.1.117): icmp_seq=7163 ttl=62 time=327 ms

basically i am trying to find all lines where time > 100 ms

user973430
  • 43
  • 5
  • This works for me, can't reproduce. I suspect that your logic to extract the time field fails on some lines and you end up with something that's not a number in `time`, but for the example input line, it works. – Benjamin W. Aug 22 '18 at 14:01

1 Answers1

3

Using awk:

awk -F'[ =]' '$(NF-1)>100' ping.txt

The time is the second-to-last field $(NF-1) when split using [ =].

PesaThe
  • 7,259
  • 1
  • 19
  • 43