Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing Content in 2 Files

Status
Not open for further replies.

davidku

Programmer
Aug 6, 2002
24
MY
Hi Gurus,

I have been trying to get the correct code but no avail.

Hope somebody can shed some lights on me.

My purpose is to list the files that exist in new.txt that are not in old.txt.

new.txt and old.txt are directory listing in 2 servers.

Thanks.

Here are my code :

awk '
BEGIN{while((getline < "old.txt") > 0) ref[$9]=$5;}
(ref[$9] !~$7){print $7} ' new.txt > results.txt



old.txt
-rw-r--r-- 1 root root 927 Aug 24 08:14 P1795922.ALT
-rw-r--r-- 1 root root 405 Aug 24 08:16 P2276720.ALT
-rw-r--r-- 1 root root 183 Aug 24 08:18 WE625408.ALT
-rw-r--r-- 1 root root 183 Aug 24 08:19 WE696622.ALT
-rw-r--r-- 1 root root 2721 Dec 5 08:44 451012.ALT



new.txt
-rw-r--r-- 1 2721 Dec 6 2005 451011.ALT
-rw-r--r-- 1 2721 Dec 6 2005 451012.ALT
-rw-r--r-- 1 2721 Dec 6 2005 451013.ALT
-rw-r--r-- 1 2721 Dec 6 2005 451014.ALT
-rw-r--r-- 1 2721 Dec 6 2005 451015.ALT
-rw-r--r-- 1 2721 Dec 6 2005 451016.ALT


 
assuming file names have no embedded spaces...
Code:
nawk '
  NR==FNR { ref[$NF]; next }
  !($NF in ref) { print $NF }
' old.txt new.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
What about using just awking out the file name and using the diff , sdiff or cmp commands?

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
mrn,

Diff does not work because you need to compare line by line.


vgersh99,

Your method works ! I just dont understand much the way you do. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top