TTYGod
Articles / Workflow

Turn a messy packing list into a useful tally

Three people send lists for a picnic and all three volunteer to bring cups. Before assigning anyone another job, put one item on each line and see which promises overlap. This exercise works entirely in a terminal and keeps the original list intact.

TTYGod editorial desk · AI-assisted launch edition · Issue ·
Share WhatsAppLinkedInEmail
Laptop on a dark desk
Laptop on a dark desk · AI-generated editorial illustration
תקציר בעברית

ברשימת ציוד משותפת כמה אנשים יכולים להבטיח להביא כוסות בשורות שונות. בתרגיל הזה ממיינים את השורות לפני הספירה כדי לרכז מופעים זהים ולקבל סיכום שאפשר לבדוק.

Start with five promises

Type printf '%s\n' cups apples cups napkins cups | sort in a macOS or Linux shell. The first part prints one item per line. The vertical bar hands that text to sort. You should see apples followed by three adjacent lines for cups, then napkins. All the sample words are lowercase plain English, so the ordering should be easy to inspect. You can run this little example as often as you like without creating a file. Explore the sort options.

Count each group

Repeat the command and add another stage at its end, so the whole line reads printf '%s\n' cups apples cups napkins cups | sort | uniq -c. Read down the count column. Apples appears once, cups three times and napkins once. The order matters because uniq counts neighbouring identical lines. If the three volunteers send their promises at different times, copies of cups can be separated in the original list. Sorting puts them together before the tally is made.

Laptop on a dark desk
Laptop on a dark desk · AI-generated editorial illustration

Decide what counts as the same item

Try replacing one cups with 'paper cups'. The quotes keep those two words together and the count splits into two categories. This is a useful editorial decision. For a table setting, all cups might count towards the same job. For a supplier order, paper and reusable cups could deserve separate lines. Read any near matches before treating the largest total as a surplus. Three volunteers promising cups does not tell you the number of cups.

Apply the method to your own text

Save a copy of your actual list as plain text with one promise per line. In its folder, type sort './picnic list.txt' | uniq -c if that is the name you chose. Inspect the result on screen. Empty lines form a group of their own and trailing spaces can split entries that look alike. Fix inconsistent labels in your editor, then repeat the same command to see the effect. For a shared list, ask each contributor to use the same names for common supplies before sending another round of promises. For further reading, browse command line for beginners books.

Before you begin

Why sort before counting the promises?

Check your result

uniq groups adjacent lines. Sorting first brings separate mentions of cups into one group.

Reference · Explore the sort options

Bookshop.org

For further reading, browse the bookshop catalogue and compare titles and editions.

This merchant link currently earns this publication no commission. Affiliate disclosure

Browse command line for beginners books

Reader notes

Read community notes

No reader notes yet.

Related articles

Mechanical keyboard and paper notes
Issue ·
Workflow

Find the note that mentions a blue envelope

You remember putting the pickup instructions in a text file. The date, the filename and the folder have slipped your mind. What stayed with you is the phrase “blue envelope.” That fragment is enough to make a small, repeatable search.

Notebook beside a terminal monitor
Issue ·
Workflow

Track down a missing draft by its filename

A friend asks for the handout you prepared last month. You remember calling it a draft, and you have a folder full of workshops, but the contents of those folders stretch over several years. Search the names before opening every document.

Portable drive beside a keyboard
Issue ·
Workflow

Measure a draft without counting its headings twice

You have a short reading to deliver and the organiser has given you a word limit. A terminal count can give you a quick baseline, provided you decide which parts of the draft belong in the count. A tiny sample makes the conventions visible.