Text Compare Online — Find Differences Between Two Texts
Text comparison highlights added, removed, and changed lines between two text blocks. Here's how diff algorithms work, what the output means, and when to use character-level vs...
Text comparison takes two text blocks (original and modified) and shows exactly what changed: lines added, lines removed, and lines that stayed the same. It’s the same technology behind git diff and code review tools, applied to any text you paste.
Use the text compare tool to compare two text blocks side-by-side with line-level and character-level highlighting.
How text comparison works
The standard algorithm is the Myers diff algorithm (1986), which finds the minimum number of additions and deletions needed to transform text A into text B. This is the algorithm used by Git, Unix diff, and most diff tools.
What it considers:
- A line is “removed” if it appears in the original but not the modified text
- A line is “added” if it appears in the modified text but not the original
- A line is “changed” if it was removed from one position and something similar (but different) appears in the other
The algorithm doesn’t detect “this line was moved from line 10 to line 50” — it sees a deletion at line 10 and an insertion at line 50. For move detection, you need more sophisticated tools.
Reading diff output
Standard unified diff format (used by Git):
--- original.txt
+++ modified.txt
@@ -1,5 +1,6 @@
Line one (unchanged)
-Line two (removed)
+Line two changed (modified)
+New line added here
Line three (unchanged)
Line four (unchanged)
-Last line removed
- Lines starting with
(space) are unchanged context lines - Lines starting with
-are removed from the original - Lines starting with
+are added in the modified version @@ -1,5 +1,6 @@indicates: original starting at line 1, spanning 5 lines; modified starting at line 1, spanning 6 lines
Side-by-side vs unified view
Unified view: Both versions in one panel, with color-coded additions and removals. Good for reading changes sequentially.
Side-by-side view: Original on the left, modified on the right, changes aligned. Better for comparing substantial rewrites.
The Text Diff tool supports both views.
Character-level vs line-level diff
Line-level diff: Highlights the entire line if anything in it changed. Useful for code — one changed character in a line is usually intentional and worth seeing in context.
Character-level (inline) diff: Within a changed line, highlights exactly which characters changed. Useful for prose — catching a single word change in a long sentence.
Line-level diff (shows full line):
- The quick brown fox jumps over the lazy dog.
+ The quick brown fox leaps over the lazy dog.
Character-level diff (shows exact change):
- The quick brown fox [jumps] over the lazy dog.
+ The quick brown fox [leaps] over the lazy dog.
Character-level diff is better for catching subtle changes in contracts, configuration values, or any text where a single character matters.
Common use cases
Contract and document review
Compare two versions of a contract or legal document. Character-level diff catches single-word changes that could have significant meaning:
- The party shall have [30] days to respond.
+ The party shall have [14] days to respond.
Configuration file comparison
Compare production and staging configs to find unexpected differences:
-database_host: db.prod.example.com
+database_host: db.staging.example.com
database_port: 5432
max_connections: 100
-log_level: error
+log_level: debug
Content editing
Compare a draft to an edited version to see what was changed. Useful when tracking changes isn’t available (PDF, plain text, or when the editor didn’t use Track Changes).
Duplicate detection
Paste two documents to check if they’re identical or near-identical. If the diff shows no changes, they’re exactly the same.
Diffing in the terminal
# Basic diff:
diff original.txt modified.txt
# Unified format (how Git shows it):
diff -u original.txt modified.txt
# Side-by-side:
diff -y original.txt modified.txt
# Ignore whitespace differences:
diff -b original.txt modified.txt
# Ignore blank lines:
diff -B original.txt modified.txt
# Ignore case differences:
diff -i original.txt modified.txt
Using git diff on uncommitted changes
# Compare working file to last commit:
git diff filename.txt
# Compare two commits:
git diff abc123..def456 -- filename.txt
# Compare with word-level highlighting:
git diff --word-diff filename.txt
Python
import difflib
original = """Line one
Line two
Line three""".splitlines(keepends=True)
modified = """Line one
Line TWO changed
Line three
New line""".splitlines(keepends=True)
# Unified diff:
diff = list(difflib.unified_diff(original, modified, fromfile='original', tofile='modified'))
print(''.join(diff))
# HTML diff (for browser display):
html_diff = difflib.HtmlDiff()
html = html_diff.make_file(original, modified)
with open('diff.html', 'w') as f:
f.write(html)
What text diff can’t detect
Semantic equivalence: if (x == true) and if (x) are logically equivalent but show as a change. Text diff is purely textual — it doesn’t understand meaning.
Formatting changes as meaningful changes: If one version uses 2-space indentation and another uses 4-space, every indented line shows as changed. Use diff -b (ignore whitespace) or run a formatter on both versions first.
Moved blocks: A paragraph moved from page 2 to page 1 shows as deleted from one location and added to another. Use a tool with move detection for this.
Related tools
- Text Diff — compare two text blocks
- How Diff Tools Work — the Myers algorithm explained
- JSON Diff — compare JSON structures
Related posts
- How Diff Tools Work: Myers Algorithm, Unified Format, and Merge Conflicts — A technical walkthrough of how diff works: the Myers algorithm, the three output…
- Diff Algorithm Explained — How Text Comparison Tools Work — Text diff tools use the LCS (Longest Common Subsequence) or Myers diff algorithm…
- Understanding Merge Conflicts — How 3-Way Diff Works — Merge conflicts occur when two branches edit the same lines differently. Learn h…
- Comparing JSON Structurally (Not Just as Strings) — Two JSON documents can be byte-different and semantically identical. Or byte-ide…
Related tool
Compare two text blocks line-by-line or word-by-word. Unified and split view. Shows added, removed, and changed segments with full color coding.
Written by Mian Ali Khalid. Part of the Data & Format pillar.