The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-02-2007
eja eja is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
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..
  #2 (permalink)  
Old 04-03-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk -F"|" ' 
BEGIN { 
	while( getline < "file.new" ) 
	{ arr[$1]=1 }
}
arr[$1] != 1 { print } 
' file.old
  #3 (permalink)  
Old 04-03-2007
eja eja is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0