LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   shell script to find the difference betwwn two file and place the difference to other (http://www.linuxquestions.org/questions/linux-general-1/shell-script-to-find-the-difference-betwwn-two-file-and-place-the-difference-to-other-629915/)

kittunot4u 03-22-2008 02:59 PM

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,

Thanks,
-Kittu.

prad77 03-22-2008 03:17 PM

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

jschiwal 03-22-2008 04:19 PM

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.

Onkar HDU Rajopadhye 07-19-2010 04:26 AM

Thanks for the useful command, jschiwal!


Regards,
Onkar


All times are GMT -5. The time now is 09:38 AM.