4 ms·
A shell script like the vocoder one in the article, this works: ping google.com | while read line; do echo $line | sed -n 's/^.*time=\(.*$\).*$/\1/p' |
by zbowling 14y ago
A shell script like the vocoder one in the article, this works:
ping google.com | while read line; do
echo $line | sed -n 's/^.*time=\(.*$\).*$/\1/p' | xargs say
done
Says the ping time to google out loud on a Mac.
- robinhouston 14y agoI know Perl is no longer fashionable, but it’s still the simplest way to do this sort of ad hoc processing I think. ping google.com | perl -ne '/time=(.*)/ && system("say", $1)' Of course it’s only a little more awkward in Ruby: ping google.com | ruby -ne '$_ =~ /time=(.*)/ && system("say", $1)' (No criticism is intended of your perfectly fine code. I enjoy comparing different ways to do things like this, and perhaps others do too.)
- gvalkov 14y agoFor the sake of comparison, here's the corresponding Python one-liner: ping google.com | python -c 'import os,re,sys; [os.system("say %s" % j[0]) for j in (re.findall("time=(.*)", i) for i in sys.stdin) if j]' I'm sure someone can come up with a shorter one-liner, but in general I think Python is simply too verbose for this kind of stuff.
- kator 14y agoAdd a delay so say can keep up: ping -i 5 8.8.8.8 | perl -ne '/time=(.*)/ && system("say", $1)'
- gautamc 14y agoOn linux I used espeak. ping google.com | ruby -ne '$_ =~ /time=(.*)/ && system("espeak", "-s 120", $1);'
- fgribreau 14y agoIn NodeJS (tested on Mac 10.7) ping g.cn | node -e "process.stdin.on('data',function(l){require('child_process').exec('say '+/time=([0-9]*)/g.exec(l+'')[1])}).resume()"
- laumars 14y agoNice code, but I think a more robust method would be using the return codes from ping: while (true) do ping -c1 -w3 google.com && say "ping" && sleep 3; done