Comparing two files and list the differences

Hi
*
I have two text files which has the file size, timestamp and the file name. I need to compare these two files and get the differences in the output format. Can anyone help me out with this.
*
cat file1.txt
474742 Apr 18 2010 sample.log
135098 Apr 18 2010 Testfile
134282 Apr 18* 2010 lib
1024 Jun 13 17:49 checksum.txt
3768008 Oct 19 11:59 reports
2644541 Oct 19 22:07 feed.log
3768008 Oct 19 22.51 quest
0 Nov 29 10:34 textfile.txt
*
cat file2.txt
474742 Apr 18
2010 sample.log
134282 Apr 18* 2010 lib
135098 May 2010 Testfile
4068258 May 23* 2011 release.txt
4068258 May 23 2011 deploy.log
3768008 Oct 19 11:59 reports
2644541 Oct 19 22:07 feed.log
10430 Nov 29 10:43 textfile.txt
*
Desired output:
Differences between two files:
*
file1:
135098 Apr 18 2010 Testfile
1024 Jun 13 17:49 checksum.txt
3768008 Oct 19 22.51 quest
0 Nov 29 10:34 textfile.txt
*
file2:
135098 May 2010 Testfile
4068258 May 23* 2011 release.txt
4068258 May 23 2011 deploy.log
10430 Nov 29 10:43 textfile.txt
*
I tried using diff but did not the appropriate output. Please help me out.

Thanks & Regards
Sendhil

---------- Post updated at 02:48 PM ---------- Previous update was at 02:45 PM ----------

Please ignore * . typo for space. Where Everett there is * its actually a blank space.

Please use code tags to preserve spaces in your output. Check the forums tutorial on how to use them:Forum Video Tutorial: How to Use Code Tags

If you posted using code tags, you wouldn't need to use * for space.

Please post in code tags so we can see what your code actually looks like.

Using grep:

~/unix.com$ grep -Fvf file2 file1

Also, please use CODE tags so you won't get annoyed with blank spaces and/or tabs

Apologize folks, earlier i posted through mobile lot of typos and auto corrections.

Here is my scenario. I need to write a script to get the differences between two files (file1. txt and file2.txt) in the desired format as mentioned. I would really appreciate your help. Thank you all in advance.


cat file1.txt
474742 Apr 18 2010 sample.log
135098 Apr 18 2010 Testfile
134282 Apr 18 2010 lib
1024 Jun 13 17:49 checksum.txt
3768008 Oct 19 11:59 reports
2644541 Oct 19 22:07 feed.log
3768008 Oct 19 22.51 quest
0 Nov 29 10:34 textfile.txt

cat file2.txt
474742 Apr 18 2010 sample.log
134282 Apr 18 2010 lib
135098 May 2010 Testfile
4068258 May 23 2011 release.txt
4068258 May 23 2011 deploy.log
3768008 Oct 19 11:59 reports
2644541 Oct 19 22:07 feed.log
10430 Nov 29 10:43 textfile.txt

Desired output:
Differences between two files:

file1:
135098 Apr 18 2010 Testfile
1024 Jun 13 17:49 checksum.txt
3768008 Oct 19 22.51 quest
0 Nov 29 10:34 textfile.txt

file2:
135098 May 2010 Testfile
4068258 May 23 2011 release.txt
4068258 May 23 2011 deploy.log
10430 Nov 29 10:43 textfile.txt

---End---

For File1 output

$ fgrep -vf file2 file1

For File2 output

$ fgrep -vf file1 file2

Try this,

awk 'BEGIN{print "File1"}  NR==FNR{a[$0]++;next} {if($0 in a){a[$0]="-1"}else{print}} END {print "\nFile2";for(i in a) { if(a != "-1" ){print i}}}' file2 file1

Did you try to use diff command?
Before 'diff' you may try to sort it first by 3rd word in the file.
--j