Useful tools to compare text files in Linux

1. diff compare files line by line
example:

diff file1 file2 

2. diff -r recursively compare directories
example:

diff -r dir1 dir2

3. compare two sorted files line by line
comm file1 file2
-1 suppress lines unique to file1.
-2 suppress lines unique to file2.
-3 suppress lines that appear in both files.

example:

comm -12 file1 file2

Print only lines present in both file1 and file2.

comm -3 file1 file2 

Print lines in file1 not in file2, and vice versa.

4. meld is a visual diff and merge tool.

It helps you compare files, directories, and version controlled projects. Free and easy to install. It is packaged for most Linux/Unix distributions, including Fedora, Ubuntu, and Suse.

example:

meld file1 file2

Leave a Reply