LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-04-2011, 08:12 PM   #1
bones996
Member
 
Registered: Sep 2003
Location: Pennsylvania
Distribution: Debian Squeeze
Posts: 106

Rep: Reputation: 15
how can I list the difference between two files?


I just upgraded my kernel to version 2.6.38 & I seem to have missed a few modules. I tried using diff to get a list of the differences between the files lsmod-2.6.35 & lsmod-2.5.38, which I created for this.

Unfortunatly I can't seem to figure out the right syntax to do what I want which is to just show me whats missing. For example, I want to subtract the lines from file1 & file2 which are the same, leaving me with the difference in file3. i.e. file3 = file1 - file2

Is this possible or am I just using the wrong program. Any help is much apppreciated. TIA
 
Old 04-04-2011, 09:51 PM   #2
nkoplm
Member
 
Registered: May 2005
Distribution: Fedora
Posts: 92

Rep: Reputation: 15
Well Im not a diff expert but this is what I would do:

given file A:
Code:
ABC
DEF
GHI
JKL
and file B:
Code:
ABC
STU
VWX
GHI
JKL
diff A B

should give:

2c2,3
< DEF
---
> STU
> VWX

which you can then grep for all the new lines in B:

diff A B | grep ^\>

ex output:

> STU
> VWX


Should work no?

Last edited by nkoplm; 04-04-2011 at 09:52 PM.
 
Old 04-04-2011, 10:09 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You could even just use grep directly.
Code:
grep -F -v -f filea.txt fileb.txt
grep -F -v -f fileb.txt filea.txt
-f takes the search patterns from a file instead of the command line.
-v inverts the search, to show what doesn't match.
-F searches for fixed strings only. Not necessary, but more efficient on big operations.

So the first example searches fileb.txt for all the lines in filea.txt, and outputs anything it doesn't find. And vice-versa for example 2.
 
Old 04-04-2011, 10:35 PM   #4
bones996
Member
 
Registered: Sep 2003
Location: Pennsylvania
Distribution: Debian Squeeze
Posts: 106

Original Poster
Rep: Reputation: 15
Thanks for the help. Grep seems to give me what I was looking for. Hopefully I get everything in the kernel this time. A year without the internet & starting back into linux with a different distro & I'm feeling like a newbie all over again Ahh, buts good to have the internet back. Thanks again.
 
  


Reply



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
Need advice on a script to search many files for list of terms, append hits to list jimmy the saint Programming 1 07-11-2010 03:59 AM
[SOLVED] How to determine difference between my application list and default one in ubuntu 10110111 Linux - Software 3 11-05-2009 10:32 AM
Kate: Append files to existing list and enable the Recent List AGazzaz Linux - Software 2 10-13-2009 08:27 PM
Downloading a list of files from a remote server using a list ralcocer Programming 2 02-11-2009 01:02 PM
How to list all files recursively, in a non-broken list? nyle Linux - Newbie 1 12-16-2008 10:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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