Searching, Reading, and Rewriting Text: Twelve Measured Guides
Twelve guides about working with text on the command line: finding lines, reading what is really in a file, and rewriting it.
Written November 11, 2026 · 6 min read
- What this page is
- Finding and matching lines (5 guides)
- Reading and inspecting text (3 guides)
- Rewriting text (4 guides)
What this page is
An index of the twelve guides on the site about working with text on the command line: finding lines, reading what is really in a file, and rewriting it. Each line states what the guide measures, in the guide's own words, and links to the guide, which carries the full code, the probe output, and the measured numbers.
Finding and matching lines (5 guides)
- Finding Lines by Prefix: look vs grep vs rg vs awk vs sed, Measured; Six ways to find the same 1,000 lines by prefix in the same million-line file. look is the fastest by a wide margin, and it earns that speed by seeking instead of scanning, but it only works on sorted input, it fails silently when the input is not sorted, and the binary-search flag the BSD manual documents does not exist in the Linux build.
- Which Lines Are in Both Files? comm vs grep vs sort|uniq vs Python, Measured; Two files, a million lines each, half a million lines in common. comm finds them in 0.14 seconds. grep needs 2.60. Python needs 0.82. The second-fastest method, sort piped to uniq -d at 0.49 seconds, is wrong: it reports a line that appears in only one file, because that line appears twice.
- grep -F vs -E vs -P, Measured: Same Pattern, Three Engines, One Silent Trap; grep -F and grep -E tie at 0.040 seconds on a plain literal, and grep -P costs 0.099 for the same 49,533 lines, 2.5 times more for nothing. LC_ALL=C halves -P and barely moves -E. And on a dotted service name the regex engines silently return 10,058 lines the fixed-string search does not, with no error and no warning.
- The Regex That Hangs: Catastrophic Backtracking, Measured Across Five Engines; Twenty-eight a's and a b. Python's re module needs 16.5 seconds to say no. grep -P gives up and errors out. ripgrep answers in about two milliseconds. Same pattern, same input, three fates, and the fix is one character.
- Pulling One Field Out of a Million JSON Lines: jq vs Python vs grep, Measured; Three tools pull one field out of a million JSON log lines. grep does it in 0.35 seconds, jq in 1.49, Python in 1.78: grep is more than four times faster than either parser. Then one nested key with the same name adds 1,000 phantom lines to grep's output, and the speed table stops being the whole answer.
Reading and inspecting text (3 guides)
- Seeing the Hidden Characters, Measured: cat -A vs sed -n l vs od -c; Seven ways to look at the same million lines. The fastest tool shows every hidden character; the flag people reach for first runs at the same speed and hides every tab; the byte-exact tool costs a hundred times more and silently drops 97 lines; and the one that prints in plain text folds a long line into three.
- Numbering a Million Lines, Measured: cat -n vs nl vs awk vs grep -n; Six ways to number the same million lines. The fastest tool numbers every line; the tool built for the job numbers only 950,000 of them by default and stops numbering entirely after one stray line; and the flag that makes nl match cat -n exactly costs 2.8 times the speed for nothing in the output.
- Hex-Dumping a 64 MiB Binary, Measured: xxd vs hexdump vs od; The same 64 MiB binary dumps in 0.68 seconds with xxd -p and 6.57 with hexdump -C, but the speed table is the least interesting part. The fastest form is also the only reversible one, the default od and hexdump output silently drops repeated lines, and bare hexdump prints byte-swapped word pairs instead of bytes.
Rewriting text (4 guides)
- Wrapping Long Lines, Measured: fold vs fmt vs awk; Six ways to wrap the same 510,000 lines to 80 columns. fold is the fastest arm and the only one whose output matches a hand-rolled awk wrapper exactly, but fmt costs 3.15 times as much and silently rewrites the shape of the file, while fold cuts a 200-character word in half and fmt refuses to break it at all.
- Tabs to Spaces and Back, Measured: expand vs unexpand vs sed vs awk vs perl; Five ways to turn tabs into spaces and five ways back, on the same million lines. The fastest tool is also the only one that aligns to tab stops; the naive substitution matches it exactly until a tab sits off a tab stop; and the flag that sets the tab width silently switches off leading-only conversion.
- Converting CRLF to LF, Measured: tr vs sed vs perl vs awk; Four ways to strip the carriage returns from the same million lines. The fastest tool is also the only one that eats carriage returns that are not line endings; the other three produce byte-identical output at different speeds; and one of them adds a newline the file never had.
- Editing a File In Place, Measured: sed -i vs perl -pi vs awk; Six ways to make the same edit to the same million-line log. The -i flag costs nothing, the backup costs nothing, and the awk temp-file form costs twice as much, but none of the six arms edits in place at all. Every one replaces the file, breaks symlinks, breaks hard links, and the two temp-file forms widen the file mode.
Also on the site
- Measured Comparisons: 30 Head-to-Head Guides, November 9–10, 2026 — the full measured series, including all twelve guides above.
- Concurrency, Async, and Waiting: Fifteen Guides on Threads, Coroutines, and Waking Up — a topical cross-hub on a different theme.
- Copying, Moving, and Splitting Files: Ten Measured Guides — a topical cross-hub on a different theme.
Related guides on this site
Keep Exploring
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.
Paste sshd -G output and get a hardening verdict on the values your server actually runs.
Paste a server block and get WebSocket, TLS, HSTS, and proxy-header verdicts.
Paste a systemd timer expression and get the specific reason it fails, the normalized form, and the past-date traps the built-in check hides.
The full sysadmin hub \u2014 systemd, cgroups, file tools, and measured Linux comparisons.