Wednesday, 11 March 2015

How To: Compare Two Files

Use the diff command to display line-by-line differences between two files. The general syntax of the diff command is:
diff FILE1 FILE2

The diff command will examine both FILE1 and FILE 2 and tell you what changes need to be made for FILE1 and FILE2 to match. Note that the diff command points to which lines need to be:

  1. Added (a)
  2. Deleted (d)
  3. Changed (c)
  4. Further lines in FILE1 identified with a less than (<) symbol and lines in FILE2 with a greater than (>) symbol.
Examples:
diff file1.txt file2.txt
Output:
2c2,3< URL: www.google.com---> URL: www.google.co.uk> Email: not@here.com
The contents of both files:
cat file1.txt
Output:
Welcome to Wherever You Are!URL: www.google.com
And 
cat file2.txt
Output:
Welcome to Wherever You Are!URL: www.google.co.ukEmail: not@here.com

No comments:

Post a Comment