![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to restore the deleted files | mail2sant | Shell Programming and Scripting | 3 | 05-14-2008 07:32 AM |
| Find duplicate value comparing 2 files and create an output | ricky007 | Shell Programming and Scripting | 2 | 02-26-2008 04:57 PM |
| find and group records in a file | thumsup9 | UNIX for Advanced & Expert Users | 20 | 04-19-2007 06:04 PM |
| Is it possible to find out how/when/who deleted particular dierectory on UNIX Aix3 | vipas | UNIX for Dummies Questions & Answers | 9 | 05-18-2004 12:04 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Help comparing 2 files to find deleted records
Hi,
I need to compare todays file to yesterdays file to find deletes. I cannot use comm -23 file.old file.new. Because each record may have a small change in it but is not really a delete. I have two delimited files. the first field in each file is static. All other fields may change. I want to know if the static data has disappeared from the file. If I use comm -23 I will get the lines that data in field 2 or 3 etc may have changed but the static data in filed 1 is the same. I did search this site and found a reply to another post that I used to solve my problem. I wrote a smal script that does work. But the problem is it is very slow. My old file has 7000 lines my new file has 4000 lines. I ran my script and 30 minutes later it still was not done. I ran it on a UNIX box that has a lot of memory and processors. It is not a hardware issue. Any sugestions? Below is my code: while read static do found="no" data=`echo "$static" | cut -d'|' -f1` while read line do echo "$line" | grep "$data" >/dev/null if [ $? -eq 0 ] then found="yes" break fi done < file.new if [ $found = "no" ] then echo "$static" fi done < file.old I am trying to keep all data on the deleted line. I could cut both files down filed 1 into smaller files and then run a comm -23 on the smaller files. But then I loose all data in the other fields. Last edited by eja; 04-02-2007 at 09:36 PM.. |
|
||||
|
anbu23,
Thank you very much. this works great. I assume with a fixed length file I could use awk's substr command? I also have two files that are fixed length where the first 20 characters is static. SO I re-wrote you helpful code to the below it also works do you see any issues with what i did I am not that good with awk. awk -F"|" ' BEGIN { while( getline < "file.new" ) { arr[substr($1,1,20)]=1 } } arr[substr($1,1,20)] != 1 { print } ' file.old |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|