How to Compare Two Text Files Quickly

Spotting the difference between two near-identical files by eye is unreliable and slow, especially for long files or changes that are a single character in a long string. A diff tool turns that into a structured list of exactly what changed, where, and by how much.

What a diff shows

A diff comparison produces a list of changes: lines that were added, lines that were removed, and unchanged context lines around the changes. The simplest case — a config value that changed — looks like this in unified diff format:

@@ -12,3 +12,3 @@
 database:
-  timeout: 30
+  timeout: 60
   max_connections: 20

Lines starting with - were in the first file. Lines starting with + are in the second file. Lines with no prefix appear in both (context). The @@ header shows approximately where in the file the change is.

When a visual diff is better than text output

CLI diff output is dense. A visual, side-by-side diff checker is much faster to scan when:

  • The changes are scattered across a long file
  • You're reviewing a document or config file (not code in a terminal)
  • The diff involves whitespace or formatting changes you want to ignore
  • You need to share the comparison with someone not comfortable with CLI tools

Side-by-side view is especially useful for seeing what text was replaced. Unified diff format shows removals and additions separately; side-by-side shows the old version on the left and the new version on the right, aligned.

Character-level differences

Line-level diffs show which lines changed. For long lines where one character is different — a URL with a typo, a connection string with the wrong port — character-level highlighting shows exactly which character changed:

- postgres://user:[email protected]:5432/myapp
+ postgres://user:[email protected]:5432/myapp
                            ^^^^^^^^^^

This is significantly faster to spot than scanning the two full URLs looking for the difference.

Whitespace-only changes: most diff tools have an option to ignore whitespace differences. If you're comparing a document that was reformatted, enable this option — otherwise every line shows as changed when only indentation changed.

Text formats that diff well

Text diffs work well on anything line-oriented: YAML, TOML, .env files, SQL scripts, plain text, CSV, log files, and code. They work less well on minified files (a single long line looks like one giant change) and binary formats. For structured data like JSON, a format-aware JSON diff shows changes at the key level rather than the character level, which is usually more useful.