Reputation: 3325
for (( x=1; $x<=300; x++ )); do ( ping world$x.runescape.com -n 20 | grep Minimum | grep -oP "(?<=Minimum = )[0-9]+(?=ms)" >> RuneScape_Ping_Output.txt ); done
What this does is ping world.runescape.com 20 times and looks for the minimum ping and stores it as its output. It will do it for world1.runescape.com all the way to world300.runescape.com as specified. The output is just a single number which the minimum ping value.
The problem I have is that I want to World number and the output as it stores. So when it's pinging world1.runescape.com instead of storing just the number 30
(30 is the ms) I want it to display World1,30
. Then if it does world233.runescape.com for example it would show World233,55
Is there any way to do this? Because sometimes there is a World122 but no World123, so unless I have something labeling each ping, it will give incorrect results by putting World124 where World123 is if no value gets return for 123, so I need to title them to get a placeholder.
Upvotes: 0
Views: 89
Reputation: 3673
You want to echo before each bit of output.
for (( x=1; $x<=300; x++ )); do
echo -n "world$x,"
ping world$x.runescape.com -n 20 | grep Minimum | grep -oP "(?<=Minimum = )[0-9]+(?=ms)"
done > RuneScape_Ping_Output.txt
I've moved the redirect outside, on the assumption that you don't want to accumulate results, just get the latest set.
Upvotes: 1