Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(standard_in) 1: syntax error when bc within if

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

like image 365
user973430 Avatar asked Dec 07 '25 10:12

user973430


1 Answers

Using awk:

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

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

like image 147
PesaThe Avatar answered Dec 10 '25 10:12

PesaThe