the evans center for sleep deprivation studies
« prev | current | next »
may 5 2004 2:41pm
entering conway, arkansas.  march 2004.
entering conway, arkansas. march 2004.

learning a few, er, gnu tricks.

I started writing shell scripts in about 1991 (whoa), and I largely use the same bag of tricks now that I used then. This has the benefit of allowing me to get work done on any lowest common denominator unix, but it also means that I get shown up by kids on a regular basis.

Here's a few new shortcuts I learned in the last few weeks while "teaching" shell scripting at work.

  • sort | uniq can become sort -u
  • grep foo *.txt | wc -l can become grep -c foo *.txt
  • sed has a -i flag that allows you to overwrite files in place, a la perl. For example, sed -i 's/fred/Fred/g' *.txt, or for the weak, sed -i .bak 's/fred/Fred/g' *.txt

I'm sure all of these features have been around for years but they're new to me so stop laughing.

Here's one that actually is pretty new: grep --color foo *.txt. Neato.