Burying the Lede

Most of us don’t write very readable shell scripts. There are plenty of things we could do better, but today I want to talk about one in particular — burying the lede. The term “burying the lede” comes from the field of journalism. Here’s the Wiktionary definition: To begin a story with details of secondary importance to the reader while postponing more essential points or facts. Like a good news article, code should tell a story. And the story should start with what’s most important. In the case of code, the most important information is the high-level functionality — a succinct summary of what the program does. In other words, write (and organize) the code top-down, as opposed to bottom-up. ...

March 11, 2014 · 2 min

Bulk Rename in Bash

Here’s a relatively simple way to rename a bunch of files from the command line. It uses sed within a command substitution to compute the new names from the old names. In this example, we’re renaming files that start with “ABC” to start with “XYZ” instead: for i in ABC*; do mv $i $(echo $i | sed -e s/^ABC/XYZ/); done You’ll have to use shell globbing (wildcards) in the first part, to determine which files will be the source of the renaming, and regular expressions in the second part to translate the old names into the new names. ...

August 26, 2011 · 1 min