Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-14-2008, 02:27 PM   #1
LQ Newbie
Registered: Dec 2007
Posts: 6

Rep: Reputation: 0
Unhappy Comparison of two files

Please let us know how to find comparison between two files. The files have same file contents.
if there are any differences in the file the output should show up the actual difference in both the files.
Old 01-14-2008, 02:48 PM   #2
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
You can use the diff command. There are also graphical frontends to this command e.g. kdiff3.
Old 01-14-2008, 03:19 PM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
For sorted files of single items, you can use the "comm" command as well. I will use it at work using Cygwin to compare inventory list from video devices. It is one of the core-utils so you should have it. You could of course use: "comm <(sort file1) <(sort file2)". In the output: Column 1 contains files unique to file1, Column 2 contains items uniq to file2 and Column 3 contains items common to both. You can suppress any column by including the column number as an option:
comm -23 <(sort file1) <(sort file2)
will print the items unique to file1. The other columns 2 & 3 are suppressed.

If you have two lists and need to verify that the items in list1 aren't in list2, you could use "grep -f file1 file2".

Refer to the manpages for comm and grep for all the options.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
comparison izza_azhar Programming 4 01-20-2005 12:57 AM
Comparison introuble Programming 1 01-18-2005 03:57 PM
OS Speed Comparison Tarential Linux - General 4 01-20-2004 10:02 PM
Comparison halobungie Linux - Newbie 4 08-10-2003 04:55 PM
*comparison in C simbo Programming 2 04-23-2003 12:05 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:56 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration