MOHAMED MOHAMED - 1 year ago 78
Linux Question

How to redirect a line fields to vars?

I have the following output from a command:

1 ( 3.032 ms
2 ( 53.825 ms
3 ( 57.146 ms
4 ( 60.792 ms
5 ( 65.873 ms

I want to redirect the fields of each line to the variables

I read all lines with:

while read LINE; do
echo $LINE #How to redirect the line fields to vars
done < <(traceroute

Answer Source


while read _ ip ip2 ms _; do
    echo "$ip $ms ms"
done < <(traceroute

Where _ is a placeholder variable.

To strip out the parentheses like in your comment :

% x='('
% echo ${x//[)(]/}                               

this is bash parameter expansion

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download