The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with Flat Files Please!! BASH (New User) cyberjax21 Shell Programming and Scripting 0 02-27-2006 09:19 PM
How to compare two flat files and get changed data jtshashidhar Shell Programming and Scripting 3 01-29-2006 10:26 PM
Column names in flat files srivsn Shell Programming and Scripting 1 12-27-2005 06:47 AM
How to compare data in two flat files and update them? rajus19 Shell Programming and Scripting 3 11-08-2005 11:13 AM
Flat Files thumsup9 Shell Programming and Scripting 2 02-02-2005 03:21 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 03-16-2007
ganesh123 ganesh123 is offline
Registered User
  
 

Join Date: Feb 2007
Location: Milwaukee
Posts: 24
Compare 2 flat files

Hi Gurus,

I searched the forum but didnt get much info.
I want to compare 2 files.

1)Newfile comes today with
2)Old file of previous day.

The files are same ,just the new files might have new records sometimes.

So I want to capture these new records in another file.

Can anyone help me in this ??

Thanks
  #2 (permalink)  
Old 03-16-2007
thestevew thestevew is offline
Registered User
  
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
If all you just want is a file containing the differences between your old and new files then try:
Code:
diff old_file new_file > diff_file
lines only in new_file will be preceded by >
  #3 (permalink)  
Old 03-16-2007
ganesh123 ganesh123 is offline
Registered User
  
 

Join Date: Feb 2007
Location: Milwaukee
Posts: 24
thanks for reply but I guess using diff will also give the records which are present in old file and not in new file.

I just want to capture the records not present in old file and present in new file.
  #4 (permalink)  
Old 03-16-2007
strobotta strobotta is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 10
The following should work:
Code:
diff old_file new_file | grep ">" | cut -b 3- > new_records.txt
grep entries that are in the newer file only, and cut the first two leading chars that diff outputs.

Records that are in the old file only will not be in the new one.
  #5 (permalink)  
Old 03-16-2007
Deal_NoDeal Deal_NoDeal is offline
Registered User
  
 

Join Date: Feb 2007
Location: Boston, MA
Posts: 64
Quote:
Originally Posted by ganesh123
Hi Gurus,

I searched the forum but didnt get much info.
I want to compare 2 files.

1)Newfile comes today with
2)Old file of previous day.

The files are same ,just the new files might have new records sometimes.

So I want to capture these new records in another file.

Can anyone help me in this ??

Thanks
If you are on solaris, you can use:

/usr/xpg4/bin/grep -v -f oldfile newfile > diff_file
  #6 (permalink)  
Old 03-16-2007
ganesh123 ganesh123 is offline
Registered User
  
 

Join Date: Feb 2007
Location: Milwaukee
Posts: 24
Thankyou everybody for your precious time.
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 05:15 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