Compare Two Texts: 6 Easy Ways to Spot Every Change cover image
Prateek Zare

Written by Prateek Zare

Software Developer with ML and Data Expertise, 8+ years of experience

Last updated
Text and Content

Compare Two Texts: 6 Easy Ways to Spot Every Change

Somebody sent back a revised version and said only that a few things changed. A few means nothing until you can compare two texts line by line and see them. This guide shows six real jobs, from contract review to config files, and which setting to pick for each one.

How to compare two texts: what a diff really does

A diff does not read for meaning. It looks for the longest set of lines that both texts share in the same order, then marks everything else as a removal or an addition. Computer scientists call that the longest common subsequence problem, and the Unix diff command from the early 1970s was built on it. To compare two texts well, you need to know that.

Take two lines that differ by one word. Text A says jumps over the dog and text B says leaps over the dog. At line level that is one removed line and one added line. Character level then runs the same matching inside the pair, so only jumps and leaps get highlighted.

Same change when you compare two texts, shown as a diff

  The quick fox
- jumps over the dog
+ leaps over the dog
2Views: unified and side by side
2Levels: line and character
2Switches: ignore case, ignore spacing
0Bytes sent to a server

Settings that change the result

Four options decide what the tool treats as different when you compare two texts. Choose them before you read the output, because the wrong setting makes a harmless edit look like a rewrite.

Settings to compare two texts and when to use them
SettingWhat it doesUse it when
Line levelMarks whole lines as added or removedLists, code, contracts with one clause per line
Char levelHighlights changed characters inside a lineOne word changed inside a long paragraph
Ignore caseTreats upper and lower case as equalText was reformatted to title or capital letters
Ignore extra whitespaceCollapses runs of spaces and tabs, trims the lineCode pasted from another editor, or double spaces
Unified viewOne column, changes inline in orderShort texts, or pasting into a review comment
Side by side viewTwo columns with filler rows to stay alignedLong documents you want to read in parallel
You compare two texts of 10 lines that differ in one line only. At line level, what does the diff show for that line?

Line level treats each line as one unit, so an edited line is a removal of the old version plus an addition of the new one. Switch to character level to see just the changed characters.

Six reasons to run a diff, by role

Pick the tab that matches your work. Each one names a typical task, the setting to try first and what to look for in the result. Each tab shows a different reason to compare two texts.

Task: you edited a 1,200 word article and the author returned a version with unmarked changes. Paste your copy in A, theirs in B and use side by side with character level on.

Look for small swaps, such as a figure changed from 14 percent to 41 percent, that a quick read would miss. Turn on ignore extra whitespace first, because word processors often add double spaces that make every line look changed.

A worked example, step by step

Here is a short example you can paste into the tool. It is a price list, the kind of text where one number matters more than a hundred words. Use it to compare two texts yourself.

Text A (original)

Basic plan: 9 dollars per month
Standard plan: 19 dollars per month
Pro plan: 39 dollars per month
Support: email only

Text B (revised)

Basic plan: 9 dollars per month
Standard plan: 24 dollars per month
Pro plan: 39 dollars per month
Support: email and chat
Annual billing: 2 months free
What the diff reports when you compare two texts in this pair
LineStatusWhy
Basic plan: 9 dollars per monthUnchangedIdentical in both
Standard plan: 19 dollars per monthRemovedOnly in A
Standard plan: 24 dollars per monthAddedOnly in B
Pro plan: 39 dollars per monthUnchangedIdentical in both
Support: email onlyRemovedOnly in A
Support: email and chatAddedOnly in B
Annual billing: 2 months freeAddedOnly in B

The totals are 2 unchanged, 2 removed and 3 added. Character level would then narrow the Standard line to the digits 19 and 24, and the Support line to the words only and and chat. That is the fastest way to confirm that a price moved by 5 dollars and nothing else on that line did. That is a clean way to compare two texts.

Add line breaks first, then compare two texts

A diff compares lines. If a whole article sits on one line, any edit marks the entire article as changed. Break the text into one sentence per line, then compare, and the output gets far easier to read.

Paste both versions, pick line or character level, and read the changes in unified or side by side view. You can copy the result as a plain patch to share. You can compare two texts as often as you like.

Open the Text Diff Tool

Limits on input size

This tool builds a full table to find the shared lines. Its work grows with the number of lines in A times the number in B. That is fine for articles, contracts and config files, and slower for huge files. Keep that in mind when you compare two texts of book length.

Size of the table needed to compare two texts by input length
Lines in ALines in BTable cells
20020040,000
1,0001,0001,000,000
5,0005,00025,000,000

Production tools such as Git use the Myers algorithm instead, published in 1986, which does far less work when two files are mostly the same. For comparing whole code repositories, use Git. For two documents of a few thousand lines or less, a browser diff is plenty.

A good fit for a browser tool

  • Drafts, contracts, essays and web copy
  • Config files and short scripts
  • Two API payloads pasted as text
  • Anything private you would rather not upload

Better with other tools

  • Whole repositories with history, use Git
  • Word processor files with tracked changes
  • Binary files and images
  • Documents of tens of thousands of lines

Why a comparison of two texts can look wrong

Troubleshooting a noisy result when you compare two texts
What you seeLikely causeFix
Every line marked changedDifferent line endings or trailing spacesTurn on ignore extra whitespace
Capitalisation changes everywhereText was reformattedTurn on ignore case
One huge removed block and one huge added blockThe text sits on one long lineAdd line breaks, then compare again
A moved paragraph shows as removed and addedA diff has no concept of movingRead the pair as one move
Changes look tiny but you expected moreCharacter level hides nothing, but the edit is smallCheck the added and removed counts

Before you compare two texts that are long lists, tidy them first. Remove repeats with the Duplicate Line Remover and put both lists in the same order with the Text Sorter. Two sorted lists show only the true differences.

Frequently asked questions

How do I compare two texts online for free?

To compare two texts online, paste the first in box A and the second in box B, then press compare. Added lines, removed lines and unchanged lines are marked, and no account is needed.

What is the difference between line level and character level when I compare two texts?

Line level marks whole lines as added or removed. Character level also highlights the exact characters that changed inside a modified line, which helps with small edits in long paragraphs.

Is it safe to compare two texts that are confidential documents in a browser tool?

The comparison runs in your browser with JavaScript, and neither text is sent to a server. Even so, follow your own organisation rules for sensitive material.

Why does my diff say every line changed when I compare two texts?

Usually the lines differ in invisible ways, such as trailing spaces, tabs or line endings. Turn on ignore extra whitespace and compare again.

Can I compare two texts that are code files?

Yes. Any plain text works, including code, config files and JSON. For whole projects with history, a version control tool like Git is a better fit.

What does the plus and minus mean in a diff?

A plus prefix marks a line that exists only in the new text, a minus prefix marks a line that exists only in the old text, and two spaces mark an unchanged line.

Sources: Wikipedia: diff, the Unix utility and its longest common subsequence basis