Compare two texts, files, or code snippets and show exactly what changed. Supports unified diff, side-by-side view, word-level highlighting, and structural diff for JSON/YAML.
bash
# Compare two files
python3 scripts/text_diff.py file1.txt file2.txt
# Compare inline strings
python3 scripts/text_diff.py --text "hello world" --text2 "hello there"
# Unified diff (patch format)
python3 scripts/text_diff.py file1.txt file2.txt --format unified
# Side-by-side comparison
python3 scripts/text_diff.py file1.txt file2.txt --format side-by-side
# Word-level diff
python3 scripts/text_diff.py file1.txt file2.txt --word-diff
# Ignore whitespace
python3 scripts/text_diff.py file1.txt file2.txt --ignore-whitespace
# JSON structural diff
python3 scripts/text_diff.py data1.json data2.json --format json
# YAML structural diff
python3 scripts/text_diff.py config1.yaml config2.yaml --format yaml
# Output diff as JSON report
python3 scripts/text_diff.py file1.txt file2.txt --output-json
CommandDescriptiontext_diff.py <file1> <file2>Compare two files (default: unified diff)--text <str> --text2 <str>Compare two inline strings--format unifiedUnified patch-style diff output--format side-by-sideTwo-column comparison--format contextContext diff (like diff -c)--format jsonStructural JSON diff--format yamlStructural YAML diff--word-diffHighlight word-level changes within lines--ignore-whitespaceIgnore leading/trailing whitespace--ignore-caseCase-insensitive comparison--context NLines of context (default: 3)--output-jsonOutput diff stats as JSON--no-colorDisable ANSI color output
0 — Files are identical1 — Files differ2 — Error (file not found, parse error, etc.)