Saturday, December 20, 2008

Fun with OS X Terminal

lynx -dump http://finance.yahoo.com/q?s=cat | grep Last | awk '{ print $3}'

This piece of code spits out the latest trading price for Caterpillar stock. Let's break it down:

lynx -dump http://finance.yahoo.com/q?s=cat
Pulls raw source from Yahoo! page using Lynx, a text-based browser

grep Last
Pulls line that contains the Last Trade

awk '{ print $3}'
Displays the 3rd term in the line spit out by grep.


2 comments:

Brian Jester said...

Dude, lynx seems to be forgotten, but it's really useful, especially if an X server isn't running and you need to visit a web site. Looks like you're greppin' and awkin' with ease. OsX's BSD roots are a selling point for me. I've been playing with OpenSolaris and Belenix in a VirtualBox VM on my WinXP box - maybe because I can't bring myself to crossover to Mac...

Kozaru said...

Brian:

Yeah, remember we were doing it in Automator, with the pretty GUI and all of the easy drag and drop steps? Well, this is easier and faster. Lynx is bitchin'.

As far as switching, it is easy to find an older iMac cheap. I had someone give me a G3 iMac for free, it is in the kids' room and working like a charm running Panther (OS X 10.3).