Comparing text in 2 files and output difference in another file.

I have 2 files of almost same text apart from 2,3 ending lines. Now I want to get that difference in another file.
e.g file1.txt is

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_livecd-lv_root
                       18G  2.4G   15G  14% /
tmpfs                 504M  264K  504M   1% /dev/shm
/dev/sda1             485M   32M  429M   7% /boot

and file2.txt is:

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_livecd-lv_root
                       18G  2.4G   15G  14% /
tmpfs                 504M  264K  504M   1% /dev/shm
/dev/sda1             485M   32M  429M   7% /boot
/dev/sdb1             7.5G  249M  7.3G   4% /media/alpha
/dev/sdc1             3.8G  1.1G  2.8G  28% /media/9C6F-1ECD

Now I want to get ending 2 lines in another file say file3.txt that is basic difference in this file.

use

diff file1 file2 > mismatchfiles

thanks for your reply. it is working but not perfectly. I'm getting some extra words in mismatchfile

Here is output of mismatchfile

6,7d5
< /dev/sdb1             7.5G  249M  7.3G   4% /media/alpha
< /dev/sdc1             3.8G  1.1G  2.8G  28% /media/9C6F-1ECD

now this 6,7d5, < , words are extra in output file. can you please tell me why I'm getting them. Thanks.

They're information on the differences between the files (line numbers in both files, deleted marker, and what the lines were). Check your system documentation for diff ( man diff ).

$$ diff file1 file2 | grep "^> " | cut -c 3- > mismatchfile 

---------- Post updated at 02:38 AM ---------- Previous update was at 02:33 AM ----------

$$ diff file1 file2 | grep "^> " | cut -c 3- > mismatchfile 

Ofcourse , CarloM is right. diff command tells us the differences between two files.So if we remove 6,7d5 or any such information from output the remaining information will be useless.Although the above code completes the asked requirement.

sorry friends...I made a mistake...I didnot paid attention on the line "can you please tell me why I'm getting them" of post #3.That is why I have written above not required code.
Now
Here is an explanation of output of diff command:

0a1,2
> line1
> line2

means append line1 and line2 after line 0 of first file

2c4
< linex                     ---> line 2 of first file
--
> liney                     ----> line 4 of second file

means change line 2 of first file with line 4 of 2nd file
and

4d5
< linez                     ---> line 4 of first file

means delete line 4 of first file

so, here a means append, c means change and d means delete
number before a or d or c refers to line number in file1
number before a or d or c refers to line number in file2

Finally, if you follow the modifications suggested by diff, then you are going to make both queried files identical.

as mentioned by @47shailesh, its the description from diff, what you can do is remove those descriptions,

diff file1 file2 | sed -ne 's/^[><] //p' > mismatchfile

Thank You very much all for spending so much time and giving me correct answer. thanks again.

If you know which file includes the other:

grep -vxFf file1 file2

Thanks. thats more useful.

So far I'm using following command to get difference of Newfile

grep -vxFf oldfile newfile

oldfile:

weather is pleasant
I am happy

newfile:

weather is pleasant
I am happy
it is raining outside

output

it is raining outsidehttp://linux.unix.com/images/editor/menupop.gif

so far its fine. but if i have new file like:
newfile:

weather WAS pleasant
 I am happy
 it is raining outside


Then output is

weather WAS pleasant
it is raining outsidehttp://linux.unix.com/images/editor/menupop.gif

Now this is the thing that I dont want... I just want that line that is completely changed (added or removed). if only few words of that line are modified then it shouldn't add that line in output. is there any way to modify this grep command to get my required result? thanks.

You would need clear criteria for what "only a few words" entails..

if criteria means number of words change in a line then i wud say 4 or less. if more than that then output that line.

I don't think that would be workable. Have a look at your original post in number 1 and tell me if changes to 4 words in a line would not constitute a change? It seems to me this thread has petered out into something else. If you have new requirements then I suggest you open a new thread with a clear description, I am closing this one.