Skip to content
86% off$349 $48.86code BF2026

Guides

Identical text files, different character count: find why

Two text files look identical but one is 6502 characters and the other 6501? Find the hidden newline, BOM, CRLF or zero-width space with Terminal or Bytepliers.

GuideUpdated 7 min read

On this page

You select all in two text files, they look the same, yet one says 6502 characters and the other 6501. Online compare tools may even report "identical". Something invisible is in one of the files, and the tool you used was either ignoring it or never showed it.

Why the counts differ

Causes, roughly from most to least common:

  1. A trailing newline. One file ends with a line break (0a) and the other does not.
  2. Line endings. Windows-style CRLF (0d0a) adds one byte per line compared with LF (0a). Across a whole file the gap is usually the number of lines, but a single stray CR gives a gap of 1.
  3. A BOM. The three bytes efbbbf at the start of a UTF-8 file. Many editors count it as one character, others hide it.
  4. A zero-width character. A zero-width space (e2808b) or joiner (e2808d), often pasted in from a web page or chat.
  5. A lookalike. A non-breaking space (c2a0) in place of a normal space, or a curly quote for a straight one. This changes bytes but usually not the character count.

Editors also disagree on how to count. Some treat CRLF as one character, some as two, and some skip the BOM. Trust byte counts, not the number an editor shows.

Step 1: narrow it down in Terminal

Open Terminal, type cd (with a trailing space), drag the folder with your files into the window and press Return. Both commands below only read files.

bash
wc -m a.txt b.txt
wc -c a.txt b.txt

wc -m counts characters (in a UTF-8 setup) and wc -c counts bytes. Compare the gaps:

Characters differ byBytes differ byLikely cause
11Trailing newline (0a), stray CR (0d), a space or a tab
13BOM (efbbbf) or zero-width space (e2808b)
01 or moreA lookalike swapped in, such as c2a0 for a space
About the line countSame as the character gapCRLF vs LF endings

Step 2: find the position with cmp and xxd

bash
cmp a.txt b.txt

cmp prints the byte position of the first difference. If it reports that one file reached EOF first, the extra content is at the very end, typically a trailing newline. A difference at byte 1 points to a BOM.

Look at the start and end of each file:

bash
head -c 16 a.txt | xxd
head -c 16 b.txt | xxd
tail -c 16 a.txt | xxd
tail -c 16 b.txt | xxd

xxd shows raw bytes in hex with readable text beside them. Watch for:

  • efbbbf at the very start: a BOM.
  • 0d0a at a line end: CRLF. A lone 0a is LF.
  • 0a as the final byte in one file only: a trailing newline.
  • e2808b, e2808d or c2a0 anywhere: zero-width space, zero-width joiner, non-breaking space.

If cmp reported a position in the middle, start reading a little earlier:

bash
xxd -s 6480 -l 48 a.txt

-s is the starting byte and -l is how many bytes to show. The command file a.txt b.txt is a quick extra check; its description often mentions a BOM or CRLF line terminators.

Step 3: see the invisible characters in Bytepliers

Terminal tells you where to look, but not always what the character is. Bytepliers has a String Inspector that names each character and highlights invisible ones.

  1. Open Bytepliers and choose String Inspector in the Inspect group, or press ⌘K and type its name.
  2. To keep two files side by side, right-click String Inspector in the sidebar and choose Open in New Window. A window from ⌘N shares inputs with the others, so the files would overwrite each other. Open in New Window gives each window its own input.
  3. Load the first file by dropping it on the editor or pressing ⌘O. Pasting the text also works.
  4. Read the stats: characters, scalars, UTF-16, UTF-8 bytes, lines, words, non-ASCII, invisible and line endings. Line endings read "Mixed (…)" when a file uses more than one kind.
  5. Repeat in the second window and compare the two sets of numbers.

Zero-width characters, a BOM, bidi controls, non-breaking spaces and other odd spaces are highlighted in the editor. The Graphemes table lists each character with its code points, Unicode name and UTF-8 bytes, but only the first 2,000, so it will not reach the end of a 6,500-character file.

Copy Revealed copies the text with each invisible character written as a code point, such as ⟨U+200B⟩. Run it on both files and paste the results into Text Diff (next step) to see exactly where they differ. Remove Invisibles strips them once you know they do not belong.

Step 4: diff with line endings turned on

If your compare tool said "identical", it was probably ignoring something. In Bytepliers' Text Diff, Ignore Line Endings is on by default, so files that differ only in CRLF vs LF can show as identical.

  1. Open Text Diff in the Inspect group.
  2. Click the Original pane and press ⌘O to load the first file; do the same in Changed for the second. Dropping files or pasting works too. Two text files opened together from Finder or the Dock also open in Text Diff.
  3. Open Options and turn Ignore Line Endings off.
  4. Check that Ignore Whitespace and Ignore Case are off (they are by default).
  5. Leave Highlight Changes By on Characters so single-character changes stand out.

The status line reads "Identical" or something like "+1 −0 · 120 unchanged". Copy Diff (⇧⌘C) copies a unified diff, and a missing final newline appears as \ No newline at end of file. Text Diff accepts up to 10 MB per side.

For a byte-level check, open Hash Generator, go to the File tab and drop in a file. The default is SHA-256. Load the second file and compare digests, or paste one into Expected checksum to see a match or mismatch.

Step 5: fix it once you know the cause

Decide which file is correct, then change the other. These commands write a new file and leave the original alone; to undo, delete the new file.

Convert CRLF to LF (removes every CR):

bash
tr -d '\r' < b.txt > b-lf.txt

Remove a BOM (confirm with xxd first that the file starts with efbbbf; this drops the first 3 bytes):

bash
tail -c +4 b.txt > b-nobom.txt

Add a trailing newline to a copy:

bash
cp a.txt a-fixed.txt && printf '\n' >> a-fixed.txt

Strip trailing newlines (all of them at the end):

bash
printf '%s' "$(cat a.txt)" > a-nonl.txt

Checklist before you decide the files match

  • Byte counts from wc -c agree.
  • cmp prints nothing (no difference).
  • Text Diff shows "Identical" with Ignore Line Endings off.
  • SHA-256 digests are equal.

If it still doesn't add up

  • Counts match but hashes differ. A lookalike replaced a character instead of adding one, commonly a non-breaking space from copied web text. cmp gives the position.
  • wc -c is equal but your editor shows 6502 vs 6501. The editor counts CRLF or the BOM differently. Trust wc -c and cmp.
  • Text Diff says "Identical". Ignore Line Endings is still on.
  • String Inspector looks the same for both files. Compare the lines and UTF-8 bytes stats. If only bytes differ, use tail -c 16 file | xxd.
  • A file prompts when you open it. Binary files offer a choice of tools, and files over 50 MB ask for confirmation. Use cmp and shasum for those.

Common questions

Does a trailing newline count as a character?

As a byte, yes: it is one byte (0a). Editors and counters differ in whether they show it, which is why two tools can disagree about the same file.

Why do some tools say my files are identical?

They are ignoring something, often whitespace or line endings. Turn those options off, or compare bytes with cmp.

Which file should I keep?

Keep whichever your downstream tool expects. A final newline and LF endings are the usual convention on macOS and Linux. A BOM and zero-width characters rarely belong in plain text.

Can I compare without installing anything?

Yes. wc, cmp, xxd, file and shasum ship with macOS. See also how to compare two text files on Mac.

Bytepliers is part of MacSuite; you can try it free for 7 days.

Every app.
One purchase.