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.

:frowning:

comm has some sorting requirements, did you try diff?

Yeah, sorting them should help here. Also, make sure your oldfile and newfile dont have spaces or funny characters in the filename.

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.

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):

tail -<n> /path/to/newfile 

If the records are multilined but with a fixed number of <x> lines for each record:

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.

sed '1,'"$((<number_of_the_day-1>*<x>))"'d' /path/to/newfile

I hope this helps.

bakunin

Looks like :confused:

grep -v -f oldfile newfile

$ 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!:b: