Linux
STUPID GAWK TRICK
This morning, for no reason that I'd care to discuss in public, I needed to rename every file in a directory to the index number of its position in the directory in asciibetical order, and add an extension.
The harmless version of this was:
ls | gawk 'BEGIN { c = 0; } c += 1 { print "mv", $0, c".jpg" }'
The version that actually does the work:
ls | gawk 'BEGIN { c = 0; } c += 1 { print "mv", $0, c".jpg" }' | bash
Better version (harmless):
ls | gawk '{ printf ("mv \"%s\" %02d.jpg\n", $0, NR) }'
Don't use the second unless, well, you know, you intend on doing it.