Text Power Tools
Change text as it flows past, and turn columns into totals and reports.
Updated
Changing Text
- Find and Replace in a Stream: sed (Journeyman): sed changes text as it flows past, replacing words with s/old/new/g and deleting lines with d, and sed -i.bak changes the files themselves while keeping a backup of each one.
Reports
- Columns and Totals: awk (Journeyman): awk splits every line into numbered fields, prints the ones you ask for, keeps only the lines that match a condition, and adds up a column, in total or per month, item or address.
- Building a Pipeline a Step at a Time (Journeyman): Build a long pipeline the way people who write them do, starting with head on a few lines, adding one stage at a time and looking after each, and read someone else's one-liner the same way, from the left.
Exercise: The Website Log Report
- Exercise: The Website Log Report (Journeyman): Change the bakery's phone number on every web page with sed, keeping a backup of each, save the five most visited pages with a pipeline, and answer five questions about a week of the website's log and orders with awk, then let a check script tell you what's done.