Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 03-22-2008, 02:59 PM   #1
LQ Newbie
Registered: Mar 2008
Posts: 1

Rep: Reputation: 0
Lightbulb shell script to find the difference betwwn two file and place the difference to other

Hi Guys,

Do any one know a shell script which can read two files and can write the unmached files to the third file.

Help me if you can,

Old 03-22-2008, 03:17 PM   #2
Registered: Mar 2008
Posts: 101

Rep: Reputation: 15
diff command will tell you the diferences bet files. Redirect the o/p to third file.
$ diff file1 file2 > file3.

Otherwise you can fine tune it with the exit status. exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.

Fedora Development

Last edited by prad77; 04-17-2008 at 03:21 AM.
Old 03-22-2008, 04: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
If the files contain simple items such as filenames and you want to know which items are unique in one or common to both, you can use the "comm" command.

This command works with sorted lists.

comm -23 <(sort file1) <(sort file2) >unique_in_file1
comm -13 <(sort file1) <(sort file2) >unique_in_file2
comm -12 <(sort file1) <(sort file2) >common_entries

See "man comm" or "info coreutils" to understand how this command works.
Old 07-19-2010, 04:26 AM   #4
Onkar HDU Rajopadhye
LQ Newbie
Registered: Aug 2006
Location: Pune
Distribution: Ubuntu, RHEL
Posts: 1

Rep: Reputation: 0
Thumbs up

Thanks for the useful command, jschiwal!



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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between normal shell and login shell Manish Linux - General 7 11-14-2012 08:30 AM
difference betwwn HTTP and HTTPS tofee Linux - Newbie 1 11-25-2006 02:31 AM
difference between shell scripting and c language gadekishore Linux - Software 5 10-17-2005 06:33 AM
Is there any difference between 2 shell scripts? tradewind Linux - Newbie 5 06-07-2004 07:52 PM
difference of shell redragon7964 Linux - Newbie 2 04-06-2004 02:20 AM > Forums > Linux Forums > Linux - General

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

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