January 29th, 2008

safety mustache

Why CLI kicks ass

GUIs are awesome and powerful, and it's really cool how many things I can do in my browser anymore, but here's why the command-line interface and toolkit-style command utilities do and will continue to totally kick ass: because you can hook all these simple little independent modules together to do really complicated things.

foreach v ( `ls *nc | cut -f 1 -d _ | uniq` )
  foreach f ( $v*nc )
    set n = `ncdump -h $f | grep long_name | cut -f 2 -d '"' | grep _ | perl -pe 's/_/ /g'`
    ncatted -h -a long_name,$v,m,c,"$n" $f

Isn't that horrible-looking? But it works. For those who don't speak shell, that means "Please go through all the NetCDF datafiles in this directory, find the 'long_name' attribute of the main variable in the metadata, and replace all the underscores in that tag with spaces. Because the modeler did it wrong."

It came to me this morning while I was waking up that it really was this easy to implement the fix, so I had to get up and write it all down while I was still in my bathrobe. It took longer to make sure I was doing it right before I ran it on the real data than it did to actually work out the details in the first place.

Go pipe! Go backticks!