Toolyard

How to Compare Two Text Files

Online

  1. Open the Diff Checker.
  2. Paste the original on the left and the new version on the right.
  3. Choose to compare by lines, words or characters. Added text is green and removed text is red.

Tick Ignore whitespace to hide changes that are only spacing or indentation, and Ignore case to treat "Hello" and "hello" as the same.

In Visual Studio Code

Select both files in the Explorer, right-click and choose Compare Selected. From a terminal: code --diff old.txt new.txt.

On the command line

  • Mac and Linux: diff old.txt new.txt, or diff -u old.txt new.txt for the familiar +/− format.
  • Windows: fc old.txt new.txt in Command Prompt.

Comparing lists

If the order of the lines does not matter, sort both lists first with Sort Lines, so the comparison shows only the entries that are really different.

Lines, words or characters

Compare by lines for code, lists and configuration files: a changed line shows as one line removed and one added. Compare by words for prose, where one new word would otherwise mark the whole paragraph as changed. Compare by characters to find the smallest differences, such as a swapped digit in an account number or a missing comma.

Differences you cannot see

  • Line endings. Windows ends each line with two characters (CR LF), Mac and Linux with one (LF). Two files that look identical can then differ on every line. On the command line, diff --strip-trailing-cr ignores this.
  • Tabs and trailing spaces. A tab and four spaces look alike on screen. Ignore whitespace hides both.
  • Look-alike characters. A non-breaking space, curly quotes from a word processor, or a Cyrillic "а" in place of a Latin "a" all show up as changes in character mode even though they look the same.

Tools in this guide

More guides