I have an array of JSON object with inside local urls and speed parameters like [{server:"192.168.0.100", speed:34}, {server:"192.168.0.130", speed:52},...]
I need to update the speed value for each server..
Reading links like Replace only if the string is found in a certain context I've tried this:
#first by first I delete the old value
sed -i 's/speed:\(.\), //g' $FILENAME
sed -i 's/speed:\(..\), //g' $FILENAME
sed -i 's/speed:\(...\), //g' $FILENAME
sed -i 's/speed:\(....\), //g' $FILENAME
#then I've tried to calculate the new one
sed -i "s/server:\"\(192.168.0...\)\"/server:\"\1\", speed:$( ping -c3 \\1 | grep rtt | cut -f 5 -d '/' ), /g" $FILENAME
But it doesn't work:
unknown host \1
sed
to external command... – Sundeep Nov 03 '16 at 11:53