0% found this document useful (0 votes)
10 views1 page

Different Ways of Comparing Two Files in Unix: Syntax Example

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Different Ways of Comparing Two Files in Unix: Syntax Example

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Different ways of comparing two files in Unix

#1) cmp: This command is used to compare two files character by character.
 Syntax: cmp [options] file1 file2
 Example: Add write permission for user, group and others for file1.
 $ cmp file1 file2
#2) comm: This command is used to compare two sorted files.
 Syntax: comm [options] file1 file2
 One set of options allows selection of ‘columns’ to suppress.
 -1: suppress lines unique to file1 (column 1)
 -2: suppress lines unique to file2 (column 2)
 -3: suppress lines common to file1 and file2 (column3)
 Example: Only show column-3 that contains lines common between file1 and
file2
 $ comm -12 file1 file2
#3) diff: This command is used to compare two files line by line.
 Description: The output indicates how the lines in each file are different, and the
steps invoved to change file1 to file2. The ‘patch’ command can be used to make
the suggested changes. The output is formatted as blocks of:
Change commands
< lines from file1

> lines from file2

You might also like