Compare Files | CMP | COMM | DIFF

Compare Files :













Command is "cmp"  -- compares byte by byte

comparing two files byte by byte and it will show the first different byte.

cmp <file1.txt> <file2.txt> 

Compare only given bytes 

cmp -n 100 <file1.txt> <file2.txt>  

to compare only given number of bytes use flag "-n"







Verbose command "-l"

cmp -l file1.txt file2.txt

The bytes started changed from 202 and then eac byte changes.

















Print only different Bytes   -- use -b flag

cmp -b file1.txt file2.txt


COMM command

Comm compares two sorted files line by line.


Display only common data between the two files

comm -1 -2 file1.txt file2.txt   // -1 remove col 1 , -2 remove column 2 and display only the common column

DIFF COMMANDS

COMM command is also used to compare line by line. Here we get three columns

-- Data that is different in file 1 and Data that is different in file 2 and common data

DIFF : Diff command only displays different lines










diff file1.txt file2.txt

-q flag says "the files differ message is displayed instead of showing what is different"

diff -q file1.txt file2.txt

-s : flag if the files are same you will get a success message

diff -s file1.txt file2.txt

It will tell you that file 1 and file 2 are identical.

-y : flag it will show all the lines parallely 










If there are any lines that are different it will show a pipe "|" symbol in the middle of that

If you want to display only those lines that are different ignore similar lines.

diff -y --suppress-common-lines file1.txt file2.txt

--suppress-common-lines  // this is used.


If you want to display all the common lines 

diff -y --left-column file1.txt file2.txt

display all the common lines on the left column and display different lines on the right column
















Comments

Popular posts from this blog

GREP Command

CURL Commands

CAT Command