Comparing two txt files - pls help

Hi,

I have some text files. I need a separate shell say 1.sh in which i can open a particular text file and compare with another txt file. For example:

1.log.txt contains

apple
ball
cat
goat

2.log.txt contains

goat
cat
lion
apple
fox

In my i.sh i need to write script to compare this two files and write the the o/p.The output should be written onto two different files such that one file contains the words that match and another contains the words that do not match.That is after i run 1.sh i should get common.txt and
notcommon.txt

common.txt should contains words present in both(common to both 1.og.txt & 2.log.txt ).i.e;

apple
ca
goat

nocommon.txt should contain the words present only in 2.log.txt and not in 1.log.txt . i.e;
lion
fox

Thanks in advance
JS

I have searched the forum and got the answer for this...I used "comm"

Thanks
JS

Remmeber that comm will work only for sorted files.

Hi,

If you are not considering the sequence of the line in the original txt file. I think you can use comm command.

Try below one.

sort file1 > file1.temp
sort file2 > file2.temp
comm -12 file1.temp file2.temp > common.txt
comm -13 file1.temp file2.temp >uncommon.txt

That is a better code than waht i tried ..
i didnot sort my source files but it was almost in a sorted way .. But its always a good method to sort the files before compiling it ..
Thanks a lot for the quote ..
Regards
JS

thanks for pointing it out .. Actually teh fils where sorted. Hence I ddint go for sorting .. The example i gave was for the name sake ..its not teh actual format of my file ..

thanks a lot for pointing it out .. because i didnt know about it .. its going to help me in the future ..

thanks a lot
JS