Text columns with cut, paste and tr
Quick answer
Linux provides small utilities for simple structured text. cut selects fields from each line, paste combines corresponding lines, and tr translates or deletes characters. These tools are useful for controlled plain-text reports with a known delimiter.
Prepare the practice environment
Use the chapter fixture described in lab-fixtures/text-streams/README.md. Run setup as a normal user in a disposable Linux environment, enter the printed directory and check pwd. Every example assumes a fresh fixture. Commands omit the terminal prompt; outputs below are not commands.
How it works
cut -d ":" -f 1 selects the first colon-separated field; fields start at 1. Without -s, lines lacking the delimiter are printed unchanged, even if they do not have the selected field. paste -d ":" joins corresponding lines with colons (default delimiter is a tab); shorter inputs supply empty fields after their end. tr reads stdin rather than a filename operand. Use LC_ALL=C tr "[:lower:]" "[:upper:]" for the ASCII examples; GNU tr is not a general Unicode case-conversion tool. Simple delimiter-separated records are not full CSV: quoted fields, embedded delimiters and embedded newlines need a parser that understands the format.
If the names file contains Mina then Reza, but the counts file is reordered independently, paste still joins first row to first row. The result can look valid while assigning a count to the wrong person. Preserve row alignment for positional pairing; data with keys requires an explicit key-based match.
Try the examples
Each fixture line has exactly two fields separated by a colon.
Expected stdout:
minarezaThe first rows are joined, then the second rows. paste does not match by a key.
Expected stdout:
mina:2reza:5Only character mapping is applied; line endings remain.
Expected stdout:
MINAREZACommon mistakes
Do not parse arbitrary CSV with cut -d comma. Do not pass a filename as a tr operand. Use input redirection or a pipe and keep transformation output separate from the input.
Practice
Extract the second field of records.txt and compare it with counts.txt. Join names and counts again and explain why row order matters.
Related references
Study: cut, paste, tr. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Text columns and translation — Knowledge Check
Apply the lesson concepts to the controlled text fixture.
Which option selects cut fields?
What does paste match by default?
How does tr normally receive data?
Why is cut insufficient for arbitrary CSV?