dif - a preprocessing front end to meld / gvimdiff / kdiff3 / tkdiff / kompare
'dif' compares files after it preprocesses them.
Preprocessing options include:
- remove comments, whitespace, timestamps
- search/replace
- keep/ignore certain lines
- json/yaml reformatting
- parse values from xls spreadsheets
- many other options (see far below)
'dif' can also be used to compare directories recursively, after optionally preprocessing each file
Overview
The graphical compare tools meld, gvimdiff, kdiff3, tkdiff, and kompare are used to compare text files on Linux
In many cases, it is difficult and time-consuming to visually compare large files because of the large number of differences
For example:
- different versions of code may differ only in comments or whitespace
- log files are often many MB of text, with some "don't care" information such as timestamps or temporary filenames
- json or yaml files may have ordering differences due to the library used to write the file
- xls spreadsheets cannot be compared easily because of the file format
Purpose
'dif' preprocesses input text files with a wide variety of options
Afterwards, it runs the Linux tools meld, gvimdiff, kdiff3, tkdiff, or kompare on these intermediate files
This allows you to concentrate on the important differences, and ignore the rest
Solutions
Problem: differences in whitespace or comments or case cause mismatches
Solution: Use options -white or -nowhite or -comments or -case
Problem: files both need to be filtered using regexes, to strip out certain characters or sequences
Solution 1: Use -grep or -ignore to filter in or out
Solution 2: Use -search -replace to supply one instance of substitution and replacement
Solution 3: Use -replaceTable to supply a file with many substitution/replacement regexes
Solution 4: Use -replaceDates to remove dates and timestamps
Problem: need to view your changes to a file on Perforce or SVN or GIT
Solution: 'dif file' will show the differences between the head revision and the local file
Problem: need to recursively compare directories
Solution 1: 'dif dir1 dir2' will iteratively compare pairs of files
Solution 2: 'dif dir1 dir2 -report' will open a GUI to compare the directories
Any preprocessing option (-comments, -white, -sort, -grep, etc) can be used when comparing directories
Usage examples
- dif file1 file2
- dif file1 file2 -white -case
- dif file1 file2 file3 -comments
- dif file1 file2 -search 'foo' -replace 'bar'
- dif file1.xls file2.xls
- dif dir1 dir2 -report