Method 1 : use command comm to compare two sorted files line by line.

Usage: comm [OPTION]... FILE1 FILE2 
With no options, produce three-column output.  Column one contains
lines unique to FILE1, column two contains lines unique to FILE2,
and column three contains lines common to both files.

  -1              suppress lines unique to FILE1
  -2              suppress lines unique to FILE2
  -3              suppress lines that appear in both files
Example:

file1.txt content

# cat file1.txt
kelvin@example.com
ryan@alpha.com

file2.txt content

# cat file2.txt
ryan@alpha.com
susan@sina.com

Show content appears in both files

#comm -12 file1.txt file2.txt ryan@alpha.com

Method 2: use command diff to compare 2 files line by line

Usage: diff [OPTION]... FILES

Example

# diff file1.txt file2.txt 1d0 < kelvin@example.com 2a2 > susan@sina.com

Method 3: use command sdiff to compare  side-by-side merge of file differences

Usage: sdiff [OPTION]... FILE1 FILE2

Example

# sdiff file1.txt file2.txt kelvin@example.com < ryan@alpha.com ryan@alpha.com > susan@sina.com
Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>