Seeing the Hidden Characters, Measured: cat -A vs sed -n l vs od -c
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.
Written November 10, 2026 · 15 min read
- The table: the three cat arms tie, and everything else costs
- The closest published work asserts without a table
- The flag people reach for first leaves tabs literal
- The long line that folds into three
What this guide is
One corpus, seven arms, three reps each. The corpus is 1,000,000 lines, 59,045,420 bytes, built from a base line of 58 characters with decorations at fixed rates: a tab on every 20th line (50,000 tabs), a CRLF ending on every 50th line (20,000 carriage returns), two trailing spaces on every 100th line (10,000 lines), a control byte and a zero-width space on every 1,000th line (1,000 of each), and ten lines of 200 repeated x characters. Every arm prints its view of the file, and every rep is checked the same way: line count, marker counts on the first rep, and a sha256 of the whole output, so a timing number can never come from a run that printed something different. The question is the one people ask before debugging a file that looks right and behaves wrong: which tool shows the hidden characters fastest, and which tools hide some of them while looking complete.
The answer is a correction in both directions. The three cat arms tie at about 0.055 seconds, so the choice among them is purely what they show, not speed, and what they show differs sharply: cat -A shows every hidden character in the corpus, while cat -v, the flag people reach for first, shows the same speed and leaves all 50,000 tabs literal. sed -n l prints the file in plain text with backslash escapes at 0.77 seconds, 14 times the cost, and folds long lines, so a million-line file prints 1,001,020 lines. od -c gives exact byte values at 5.7 seconds, 103 times the cost, and silently drops 97 output lines to star elision on this corpus. The traps decide more real debugging jobs than the speed table does: a grep for ^I over cat -v output concludes the file has no tabs, a line count over sed -n l output over-counts by the fold count, and a line count over default od -c output under-counts by the elision.
The table: the three cat arms tie, and everything else costs
Wall seconds, medians of three runs, fresh tonight. Every rep returned rc=0, and every arm's output sha256 was identical across its three reps.
cat -A: fresh median 0.0552, reps 0.0772, 0.0540, 0.0552. Night before: 0.0558, reps 0.0554 to 0.0565. Prints 1,000,000 lines.cat -vet: fresh median 0.0571, reps 0.0558, 0.0571, 0.0572. Night before: 0.0534, reps 0.0532 to 0.0539. Prints 1,000,000 lines.cat -v: fresh median 0.0547, reps 0.0542, 0.0547, 0.0572. Night before: 0.0544, reps 0.0540 to 0.0547. Prints 1,000,000 lines.sed -n l: fresh median 0.7739, reps 0.7734, 0.7739, 0.7745. Night before: 0.7675, reps 0.7623 to 0.7692. Prints 1,001,020 lines.od -c: fresh median 5.7099, reps 5.7099, 5.8208, 5.6827. Night before: 5.6745, reps 5.6513 to 5.7654. Prints 3,690,243 lines.od -An -c: fresh median 5.6923, reps 5.7170, 5.5206, 5.6923. Night before: 5.5089, reps 5.4783 to 5.7879. Prints 3,690,242 lines.od -v -c: fresh median 5.7396, reps 5.7396, 5.7995, 5.6550. Night before: 5.5847, reps 5.5658 to 5.5869. Prints 3,690,340 lines.
Against cat -A at 0.0552 seconds tonight, cat -v ties at 0.99 times and cat -vet ties at 1.03 times, so the three-way tie is the claim and the exact ordering is one machine's: the night before, cat -vet was the fastest of the three at 0.0534 against cat -A at 0.0558, and tonight the order reverses. sed -n l costs 14.0 times (13.8 the night before), and the three od arms cost 103 to 104 times (102 the night before for od -c). The ranking is identical on both nights and every ratio moved by less than two percent, so the ordering is stable and the exact ratios are one machine's.
Two cells are noisy and the guide says so rather than hiding it. The cat -A first rep is the cold spike both nights: 0.0772 seconds tonight and 0.0782 the night before against medians near 0.054 to 0.056. A one-run timing of cat -A would report about 40 percent more than the steady cost. The od -An -c second rep tonight is 5.5206 against 5.6923 to 5.7170 on the other two, and the night before it spanned 5.4783 to 5.7879, the widest range in the table. The cat cells sit near the spawn-and-read floor at 0.054 to 0.057 seconds, so treat the three-way cat tie as order-of-magnitude; the sed and od gaps, 14 times and about 100 times, are the stable claims. Throughput on the 59 MB input: cat -A reads about 1,070 MB/s, sed -n l about 76 MB/s, od -c about 10 MB/s.
The closest published work asserts without a table
The closest published work is a methods guide, not a measurement, and the distinction is the gap this probe fills. The CopyProgramming hidden-characters guide covers cat -vet and -A, od -c, and sed and tr as methods, with worked examples and a zero-width-space walkthrough, but no timing table, no corpus, no reps, and no output verification. It calls cat -vet the fastest and most common method and states that cat -A gives identical output to cat -vet, both as assertions.
The guide's other methods are a different job from this probe's. Its sed and tr method removes characters; this probe's sed -n l arm displays them, and no sed -n l display appears in the guide at all. Its od -c example finds a zero-width space in one short line; this probe counts the elision across 3.7 million output lines. The Unix Power Tools piece on cat -v and od -c states the same manual facts this guide relies on, that -v excepts tab and line feed from caret notation, with no measurements. The counting tables time line counting, which does not display hidden characters at all. None of them runs the seven arms on one corpus with reps and verified outputs.
The flag people reach for first leaves tabs literal
cat -v is the flag people type first, and on this corpus it is a trap. Its output has zero ^I markers and all 50,000 literal tab bytes, verified by exact count on the first rep tonight and the night before. The manual states why directly: -v uses caret and M- notation except for line feed and tab. The tab is the one hidden character cat -v refuses to show, and it is also the most common one in the corpus at 5 percent of lines. Anyone grepping cat -v output for ^I to answer whether the file has tabs concludes that it has none, with a zero exit code and no warning.
cat -A shows all of them. Its first-rep marker counts tonight, all exact: ^I 50,000, ^M 20,000, $ 1,000,000, the trailing-spaces ending ^M$ 10,000, ^A 1,000, M- 3,000. The trailing-spaces count is worth a sentence, because the ending is ^M$ and never $: every trailing-space line is also a CRLF line, since every 100th line is also every 50th, so the two trailing spaces sit before the carriage return. A reader searching for lines ending in two spaces plus $ finds nothing and concludes the file has no trailing spaces. The zero-width space shows in three notations across the arms, and the trap file below shows all three: cat -A prints M-bM-^@M-^K, sed -n l prints \342\200\213, and od -c prints 342 200 213, with the 342 byte counted exactly once in the trap output.
The manual's decomposition is the whole story for the cat arms: -A is exactly -vET, -e is -vE, -t is -vT. -E appends $ at each line end, -T shows tabs as ^I, and -v alone supplies only the caret and M- notation with the tab exception. The only difference between cat -v and cat -A on this corpus is the -E and -T parts, and those two parts are the difference between seeing the tabs and missing all 50,000 of them.
The long line that folds into three
sed -n l printed 1,001,020 lines for a 1,000,000-line file, exactly the predicted count, tonight and the night before. The fold is the l command's wrap: it lists the current line in a visually unambiguous form, breaking it at 70 characters by default, and the wrap applies to the escaped length, not the raw length. The 1,000 decorated lines each fold once, adding 1,000 lines, and the ten 200-character lines each fold twice, adding 20. Anyone counting lines in sed -n l output over-counts by the fold count, and the fold count depends on the escapes, so it changes with the file's hidden characters rather than its line count.
The trap file shows the fold line by line. It is eight lines: a tab line, a CRLF line, a trailing-spaces line, a zero-width-space line, a control-byte line, a 200-character line, a plain line, and a last line with no trailing newline. sed -n l prints ten lines for it, because the 200-character line folds twice into three. The decorated corpus line folds once too: measured tonight, its escaped form is 78 characters plus the trailing $, 79 in total, wrapping at 70 into a 70-character first line and a 10-character second line. The banking run's note said 74 characters; the re-measurement tonight corrects it to 78, and the fold count is unchanged either way, since both lengths sit between 71 and 140.
The trap file's other checks all pass, tonight and the night before. Under cat -A, line 2 ends ^M$, line 3 ends $, line 4 has M-b for the zero-width space, line 5 has ^A for the control byte, the 200-character line stays on one line at 201 characters including the $, and the final line with no trailing newline has no $. Under cat -v, the first line has a literal tab and no ^I. Under sed -n l, the output has \t and ten lines. The sed output is the only one of the three whose line count disagrees with the file's line count, and it disagrees by exactly the fold count.
The star that eats 97 rows
Default od -c printed 3,690,243 lines against the no-elision count of 3,690,340, exactly 97 lines silently replaced by *, tonight and the night before. The no-elision count is the ceiling of the byte count over 16 plus one final offset line, and od -v -c prints exactly that count, 3,690,340 lines. od -An -c elides identically at 3,690,242 lines, one fewer than default od -c, the missing final offset line, since -A n suppresses offsets. The 97 elided lines come from the ten 200-character lines: each one's twelve identical 16-byte rows collapse to one row plus a *. The elision count is corpus-specific and this guide does not quote it as a rate; a file of repeated lines widens it, a file of unique lines narrows it to zero.
The trap file shows the same behavior at small scale. Its 259 bytes need 18 rows with no elision, and od -v -c prints exactly 18. Default od -c prints 8, because the 200-character line's twelve identical rows collapse to one row plus a *, eliding 10. Default od output is lossy for line-by-line parsing: pass -v, or use cat -A when the question is what the characters are rather than their byte values.
The byte-identical pair
cat -vet output and cat -A output have the same sha256 on all three reps each, tonight and the night before. Same tabs, same carriage returns, same line endings, same control bytes, byte for byte. The two commands take different spellings to the same file: cat -vet at a fresh median of 0.0571 seconds, cat -A at 0.0552, a tie within the noise on both nights. That is the one place where the choice is not a trade-off at all. The manual says -A is -vET and -vet spells the same three flags out, and the probe confirms the manual with a hash.
That is also the pattern the line-numbering guide found the night before, where nl -ba output was byte-identical to cat -n output at 2.76 times the cost. Here the pair costs the same, so there is nothing to choose between them on output or speed. The real choice is cat -v against cat -A: same speed, different output, and the cheaper-looking flag is the one that hides the tabs. Portability is the only remaining reason to spell it out: -A is a GNU shorthand, and -vet is the portable spelling for macOS and BSD systems, where -A does not exist.
Checklist
- Before grepping for tabs, check the flag:
cat -vprints zero^Ifor 50,000 tabs, because-vexcepts tab from caret notation; usecat -Aorcat -vet. - Before counting lines in
sed -n loutput, check the fold count: a million-line file prints 1,001,020 lines, and the fold depends on the escaped length at a 70-character wrap, so it changes with the hidden characters. - Before trusting default
od -cline counts, check the elision: 97 lines collapse to*on this corpus, and 10 of 18 rows on the eight-line trap file; pass-vfor the full count. - Before paying for
od -covercat -A, check the question: byte values cost 103 times the speed, andcat -Ashows every hidden character in the corpus at 0.055 seconds. - Before quoting a ratio, check the range:
cat -Afirst rep is 0.0772 seconds against a 0.0552 median on both nights, so single runs lie. - Before reusing these numbers, check the setup: WSL2, 32 CPUs, cat and od 9.4, sed 4.9, tmpfs, warm page cache, one thread per arm, one 1,000,000-line corpus with 5 percent tabs, 2 percent CRLF, 1 percent trailing spaces, sha256 recorded in the probe log.
Related guides on this site
- Hex-Dumping a 64 MiB Binary, Measured: xxd vs hexdump vs od
- Numbering a Million Lines, Measured: cat -n vs nl vs awk vs grep -n
- Finding Lines by Prefix: look vs grep vs rg vs awk vs sed, Measured
- Tabs to Spaces and Back, Measured: expand vs unexpand vs sed vs awk vs perl
Sources
- Linux man-pages, cat(1) — read 2026-11-10:
-Ais equivalent to-vET,-vuses caret andM-notation except for line feed and tab,-Edisplays$at the end of each line,-Tdisplays tab as^I. Box runs GNU coreutils 9.4; the manual text is coreutils 9.11 and every cited behavior was exercised by the probe itself. - Linux man-pages, sed(1) — read 2026-11-10: the
lcommand lists the current line in a visually unambiguous form, breaking it at width characters, and-l Nsets the desired line-wrap length. Box runs GNU sed 4.9; the manual text is GNU sed 4.10 and every cited behavior was exercised by the probe itself. - Linux man-pages, od(1) — read 2026-11-10:
-vdoes not use*to mark line suppression,-Asets the address radix withnfor none,-cselects printable characters or backslash escapes. Box runs GNU coreutils 9.4; the manual text is coreutils 9.11 and every cited behavior was exercised by the probe itself. - CopyProgramming, How to See Hidden Characters in the Terminal — read 2026-11-10: covers
cat -vetand-A,od -c, and sed and tr as methods with worked examples, callscat -vetthe fastest and most common method, and statescat -Agives identical output tocat -vet. No timing table, no corpus, no reps, and no output verification; its sed and tr method removes characters rather than displaying them, and nosed -n ldisplay appears in it. The closest published work, and the gap this probe fills. - Unix Power Tools, Show Nonprinting Characters with cat -v or od -c — read 2026-11-10: states that
-vdoes not convert tab and trailing-space characters to a visible form without the-tand-eoptions, and thatod -cshows characters in backslash escapes. Prose explanation with no measurements. - Veldica, Hex-Dumping a 64 MiB Binary: xxd vs hexdump vs od, Measured — the sibling guide: measures the
*elision first, on a 64 MiB binary, where defaultodandhexdumpprint 3 lines for an all-zeros file against 4,194,305 with-v. This guide measures the same elision on a text corpus; it does not re-teach the hex dump. - Veldica, Numbering a Million Lines: cat -n vs nl vs awk vs grep -n, Measured — the sibling guide: measures line numbering on a million lines, and found the same byte-identical-pair pattern,
nl -baoutput equal tocat -noutput. This guide shows hidden characters; it does not number lines.
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.