The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Emergency UNIX and Linux Support !! Help Me!!
.
google unix.com



Emergency UNIX and Linux Support !! Help Me!! Post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help to find the time difference between the lines sathik Shell Programming and Scripting 4 09-14-2009 07:35 AM
find difference in file column... malcomex999 Shell Programming and Scripting 1 04-15-2009 06:31 AM
script to compare first column of two files and find difference adityam Shell Programming and Scripting 3 10-22-2008 10:02 AM
RCS - Find difference between 2 different versions of a file kelangovan UNIX for Advanced & Expert Users 1 05-20-2008 09:47 AM
Difference between locate and find camerja1 UNIX for Dummies Questions & Answers 1 06-25-2002 02:55 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 Display Modes
  #1 (permalink)  
Old 09-30-2009
ganesh_248 ganesh_248 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
Unhappy to find difference between two files

I have a file which gets appended with records daily..for eg. 1st day of the month i get 9 records ,2nd day 9 records .....till the last day in the month...the no of records may vary...i store the previous days file in a variable oldfile=PATH/previousdaysfile....i store the current days file in a variable newfile=PATH/currentdayfile. i only want the records that is present only in the current days file...

i tried comm -23 $newfile $oldfile...but i am getting error.

Please help me out.

  #2 (permalink)  
Old 09-30-2009
varontron varontron is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 110
comm has some sorting requirements, did you try diff?
  #3 (permalink)  
Old 09-30-2009
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
If you know the number of records (you said they vary, but maybe the number is known somehow), then simply "tail" the last <n> records, where <n> is the number of records (i suppose records to be lines):

Code:
tail -<n> /path/to/newfile
If the records are multilined but with a fixed number of <x> lines for each record:

Code:
tail -$((<x>*<n>)) /path/to/newfile
If the records for the present day are not all stored already you still might still know the number of records from the beginning which you have to filter out, leaving the non-filtered records as new. Example: 3 records per day, today is the 10th day of the month. You will have to filter the first 9 days (meaning 9*3=27 lines) and everything left will be from today.

Code:
sed '1,'"$((<number_of_the_day-1>*<x>))"'d' /path/to/newfile
I hope this helps.

bakunin

Last edited by bakunin; 09-30-2009 at 10:13 AM..
  #4 (permalink)  
Old 09-30-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 229
Quote:
Originally Posted by varontron View Post
comm has some sorting requirements, did you try diff?
Looks like
  #5 (permalink)  
Old 09-30-2009
ccj4467 ccj4467 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 10
grep -v -f oldfile newfile
  #6 (permalink)  
Old 10-01-2009
ganesh_248 ganesh_248 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
Smile

$ comm -23 "$oldfile" "$newfile"

i am getting this error
comm: cannot open

---------- Post updated at 09:49 AM ---------- Previous update was at 09:34 AM ----------

Thank You guys for your valuable suggestions.
comm -23 "newfile" "oldfile" worked fine...
i made a small mistake in assigning the files to variables.That's why i was getting error.

Thanks once again!
  #7 (permalink)  
Old 09-30-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
Yeah, sorting them should help here. Also, make sure your oldfile and newfile dont have spaces or funny characters in the filename.
Code:
sort "$newfile" >"$newfile".sorted
sort "$newfile" >"$oldfile".sorted
comm -23 "$newfile".sorted "$oldfile".sorted
I think adding the -u (uniqify) parameter to the sort command makes sense here.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:30 AM.


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