How do I filter out any pings that are under a certain ms, ie, only echo ping responses above 500ms to the text file?IP=$1SECONDS_Between_Pings=$2ping -i $2 $1 | while read pong; do echo $(date) $pong; done >> ~/Downloads/pings_file_$(date +%Y-%m-%d).txt
How can I filter ping results by time?
shell script;text processing;ping
grep with extended regex:ping ... | grep --line-buffered -E 'time=([0-9]{4}|[5-9][0-9]{2})' | ...This will match any line with time= followed immediately by either:Any 4 digits (1000+ ms).One digit 5-9 followed by any 2 digits (500-999 ms).--line-buffered works around issues caused by grep's default output buffering when used in a pipe chain. Not needed when grep is the last link in the chain.