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! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-23-2012, 01:54 AM
|
#1
|
Member
Registered: Jan 2012
Posts: 46
Rep: 
|
Compare two files?
Hi Sir/Hello Friends,
My question is, there is one configuration file which had written some day before. Now i have modified that file by adding some more lines of code. Now my task is to compare and check where all i modified that file. Is there any method in linux to compare those files. Can any one help me out.
Regards,
Shahid Nx
|
|
|
Click here to see the post LQ members have rated as the most helpful post in this thread.
|
04-23-2012, 01:56 AM
|
#2
|
Senior Member
Registered: Mar 2012
Posts: 1,882
|
and 'man diff' for options
|
|
|
04-23-2012, 02:05 AM
|
#3
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
Another command you might want to look at: comm
Code:
comm <options> file1 file2
Hope this helps.
|
|
|
04-23-2012, 02:15 AM
|
#4
|
Member
Registered: Jan 2012
Posts: 46
Original Poster
Rep: 
|
But the out put that diff cmd is giving i m not getting that.
is it possible in linux where it compares the two files and display only lines that are not present in old file. means if old file is of 100 lines and in new file i added 10 more lines to it. So is there any way to display only these added lines. Plz share if any idea
|
|
|
04-23-2012, 02:16 AM
|
#5
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
|
Quote:
My question is, there is one configuration file which had written some day before. Now i have modified that file by adding some more lines of code.
|
Did you make the changes in that same file? Did you take backup of that file before making changes?
|
|
|
04-23-2012, 02:17 AM
|
#6
|
Senior Member
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,900
|
Install Meld, open the application tell it what files you want to compare and it will show you what lines are different. I use it alot for optimising package lists.
|
|
|
04-23-2012, 02:18 AM
|
#7
|
Member
Registered: Jan 2012
Posts: 46
Original Poster
Rep: 
|
Yes sir i have taken the back up of that file. nw i have both old and new file.
|
|
|
04-23-2012, 02:19 AM
|
#8
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
Both files need to be sorted, otherwise both comm and diff won't work (as stated in the man pages).
If the files are sorted, comm can do what you want/need:
Code:
comm -3 file1 file2
See man page for details.
If the files cannot be sorted: Have a look at k3lt01's suggestion.
Hope this helps.
|
|
|
04-23-2012, 02:21 AM
|
#9
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
And as a generic suggestion:
Code:
man -k search_term| egrep '\(1|8\)'
In your case:
Code:
man -k compare| egrep '\(1|8\)'
bzcmp [] (1) - compare bzip2 compressed files
bzdiff [] (1) - compare bzip2 compressed files
cmp [] (1) - compare two files byte by byte
comm [] (1) - compare two sorted files line by line
compare [] (1) - mathematically and visually annotate the difference between an image and its reconstruction
diff [] (1) - compare files line by line
diff3 [] (1) - compare three files line by line
git [] (1) - diff-files - Compares files in the working tree and the index
git [] (1) - diff-index - Compares content and mode of blobs between the index and repository
git [] (1) - diff-tree - Compares the content and mode of blobs found via two tree objects
infocmp [] (1) - compare or print out terminfo descriptions
ldapcompare [] (1) - LDAP compare tool
lzcmp [] (1) - compare LZMA compressed files
lzdiff [] (1) - compare LZMA compressed files
msgcmp [] (1) - compare message catalog and template
ndiff [] (1) - Utility to compare the results of Nmap scans
ntfscmp [] (8) - compare two NTFS filesystems and tell the differences
rcsdiff [] (1) - compare RCS revisions
test [] (1) - check file types and compare values
tiffcmp [] (1) - compare two TIFF files
zcmp [] (1) - compare compressed files
zdiff [] (1) - compare compressed files
zipcmp [] (1) - compare contents of zip archives
Cheers,
Tink
|
|
1 members found this post helpful.
|
04-23-2012, 02:22 AM
|
#10
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
|
You can also get the clear-cut visual difference between two files using this command -
Code:
# sdiff file1.txt file2.txt
No need to install any other software/package.
|
|
2 members found this post helpful.
|
04-23-2012, 02:33 AM
|
#11
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,481
|
you can try: diff file1 file2 | grep '^<' or diff file1 file2 | grep '^>'
|
|
|
04-23-2012, 03:59 AM
|
#12
|
Member
Registered: Jan 2012
Posts: 46
Original Poster
Rep: 
|
@Satyaveer Arya: Yes sir sdiff command helps,i got my output.
Thanks To all.
|
|
|
04-23-2012, 04:15 AM
|
#13
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
|
Glad to know the the problem solved out and the command worked out for you. 
|
|
|
All times are GMT -5. The time now is 06:44 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|