Websites and web tools
Automating diff checks: practical patterns
A diff tool shows what changed between two versions of a file. Used by hand, it catches typos in a contract revision. Automated, it can warn you when a price list, a policy page or a configuration file changes without anyone saying so. This page covers the main diff modes and a few scripts that run on their own.
What a diff actually compares
| Mode | Unit compared | Good for |
|---|---|---|
| Line diff | Whole lines | Code, configuration, CSV exports |
| Word diff | Words within changed lines | Prose such as terms of service or service descriptions |
| Character diff | Single characters | Spotting one changed digit in a price or part number |
| Binary compare | Bytes | Checking whether two images or PDFs are identical |
Line diff is the default in most tools. For paragraphs of text, a whole paragraph often sits on one line, so a single comma change marks the whole line as different. Switch to word mode for prose.
The commands worth knowing
diff -u old.txt new.txtprints a unified diff with a few lines of context around each change.diff -q a bonly reports whether the files differ, which is handy inside scripts.cmp a bcompares byte by byte and is fine for binary files.git diff --word-diffshows changed words inline for files in a Git repository.git diff --statsummarizes how many lines changed per file.
diff returns exit status 0 when files match, 1 when they differ and 2 when something went wrong, such as a missing file. Scripts should treat 2 as an error, not as a change.
Pattern 1: watch a page for changes
- Fetch the page on a schedule and save only the text you care about, for example with a tool that strips HTML.
- Compare it with yesterday's saved copy using
diff -u. - If the exit status is 1, email or message the diff to yourself.
- Replace yesterday's copy with today's.
Strip things that change on every load first: timestamps, session tokens, rotating banners. Otherwise every run reports a change and the alert becomes noise you learn to ignore.
Pattern 2: check exports before import
Before you import a new parts price file or an inventory feed into your site, diff it against the last import. A sudden change in thousands of lines usually means a column moved or the supplier changed the format, not that every price changed overnight.
Pattern 3: review configuration in version control
Keep site settings, redirect rules and robots files in Git. Every change then has a readable diff and an author, and git log -p shows how a file evolved. That history is the fastest way to find which edit broke a booking form.
Worked example: time saved
Suppose you manually check 40 pages of a supplier catalog each week and each check takes 3 minutes. That is 120 minutes a week, or about 104 hours a year. A scripted diff that only alerts you on change cuts the routine part to near zero; you then spend time only on the pages that actually changed.
Mistakes to avoid
- Comparing files with different line endings. Normalize with a tool or use
diff --strip-trailing-cr. - Diffing raw HTML when you care about visible text.
- Sending every alert to a shared inbox where nobody owns it.
- Pasting confidential documents into online diff sites. Use a local tool for anything private.