Scripts – How to Write an Awk Script to Catch Ping’s Time awkscripts In this line: Reply from 10.11.12.13 time=1035ms how to write an awk script which brings out just 1035. Best Answer You can use for example: ping host | awk 'BEGIN {FS="[=]|[ ]"} {print $11}' or, better to stop ping after sending one or more packets: ping -c 1 host | awk 'BEGIN {FS="[=]|[ ]"} NR==2 {print $11}' or ping -c 5 host | awk 'BEGIN {FS="[=]|[ ]"} NR>=2&&NR<=6 {print $11}' If you refer at this string: "Reply from 10.11.12.13 time=1035ms" and not at the output of ping command, you can use: echo "Reply from 10.11.12.13 time=1035ms" | awk 'BEGIN {FS="[=]|ms"} {print $2}' Related SolutionsUbuntu – How to process multi-line records with awk in a bash script With awk, you can change the record separator. By default it is a newline, so each line of the file is a record. If you set the RS variable to the empty string, awk will consider records to be separated by blank lines: awk -v name="KFC" -v RS="" '$0 ~ "Restaurant: " name' example.txt Ubuntu – Why the bash script only outputs one line on echoing awk variable You're not using the $i variable inside the loop for i in "${addresses[@]}"; do # ..^ echo $addresses, disable, , , >import.csv # .......^^^ should be: echo $i, ... done For an array variable, when you print the variable without specifying an index, bash seems to give you just the first element. $ x=( one two three ) $ echo $x one Related QuestionUbuntu – How to process multi-line records with awk in a bash scriptUbuntu – Why the bash script only outputs one line on echoing awk variableUbuntu – How to use double substitution in awkUbuntu – How to use sort on an awk print commandUbuntu – Why does this awk script that runs on CentOS not run on Ubuntu
Best Answer
You can use for example:
or, better to stop
ping
after sending one or more packets:or
If you refer at this string: "Reply from 10.11.12.13 time=1035ms" and not at the output of
ping
command, you can use: