Unix File compare commands


1. cmp

2. diff

3.comm

cmp: It comapares 2 files.If files are same it returns promp or else it returns the message where the difference encountered.

Syn: $ cmp file1 file2

Ex: $ cmp  paypal.txt   funpal.txt

diff: This command compares 2files like cmp.If any difference found in 2 files it displays those lines.

Ex:


$ diff  paypal.txt   funpal.txt

comm : Used to compare 2 sorted files.It provides out put in 3 columns.

* In first column displays uniq lines of first file.
* In second column displays uniq lines of second file
* In third column displays common lines in 2 files.

Ex:-

Step1 : Create two files with some data

$ cat> paypal.txt
risk
payments
ebay
uv
norkom

$ cat> funpal.txt
foodball
cricket
crems
ebay
payments

Step2: Sort above files and store the data into another 2 different files

$ sort  paypal.txt   paypal1.txt   [Enter]

$ sort  funpal.txt   funpal1.txt   [Enter]

Step3: Use comm command

$ comm paypal1.txt   funpal1.txt  [Enter]

** output shows in 3 different columns.

Followers