LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 01-13-2011, 03:51 AM   #1
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215
Blog Entries: 1

Rep: Reputation: 21
need some help on using diff command


hi all,

i have file1 and file2.
Quote:
File 1 contents are,
eingston
ewinston
eononono
edpdpdpd
Quote:
File 2 contents are,
edsdsdsd
ewinston
edpdpdpd
eingston
Here i want to compare these two files with diff command and need to take the common things in a separate file. File contents are 7 strings in length and everything will start with the character e.
File 3 contents should be
Quote:
ewinston
edpdpdpd
Please help me.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-13-2011, 03:59 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Your examples have 3 entries that are in both files, not 2......

To use diff (or in this case comm) you need to have sorted in-files. If they are sorted then the following will show entries that are in both files: comm -12 file1 file2

Example run:
Code:
$ cat file1
edpdpdpd
eingston
eononono
ewinston

$ cat file2
edpdpdpd
edsdsdsd
eingston
ewinston

$ comm -12 file1 file2
edpdpdpd
eingston
ewinston
Hope this helps.
 
2 members found this post helpful.
Old 01-13-2011, 04:10 AM   #3
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215
Blog Entries: 1

Original Poster
Rep: Reputation: 21
thanks drunna, it worked.
I didnt sort the files first. Now it works as i want. Thanks again, One more question.
In file1, eononono was remaining or we can say its not in file2. I want to take this in a separate file.
I need the same from file2. Please help me

Last edited by kingston; 01-13-2011 at 04:14 AM.
 
Old 01-13-2011, 04:36 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Files that are unique to file1: comm -23 file1 file2
Code:
$ comm -23 file1 file2
eononono
Files that are unique to file2: comm -13 file1 file2
Code:
$ comm -13 file1 file2
edsdsdsd
Hope this helps.
 
1 members found this post helpful.
Old 01-13-2011, 05:28 AM   #5
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215
Blog Entries: 1

Original Poster
Rep: Reputation: 21
thanks man, you are great.
It worked well.
 
Old 01-13-2011, 05:37 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome
 
  


Reply


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
Diff Command is possible for me? admod Linux - Virtualization and Cloud 1 11-21-2010 10:42 AM
diff command advice john83reuben Linux - Newbie 2 12-06-2009 09:50 AM
Question on diff command just.srad Programming 4 04-05-2008 05:01 AM
How to use 'diff' command ursusman Linux - Newbie 1 03-08-2007 05:29 AM
help on diff command anandss2004 Programming 2 11-01-2005 01:58 PM


All times are GMT -5. The time now is 01:01 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration