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 > 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
Comparison Unix and Windows file sysytem localp UNIX for Dummies Questions & Answers 1 04-11-2008 04:02 AM
Output format - comparison with I/p file velappangs Shell Programming and Scripting 1 04-03-2008 06:31 AM
file comparison script tiger99 Shell Programming and Scripting 1 01-30-2008 10:47 AM
File Comparison net_shree Shell Programming and Scripting 19 01-10-2008 08:00 PM
File Time Comparison Question pc9456 UNIX for Advanced & Expert Users 2 07-23-2003 03:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-12-2008
er_ashu er_ashu is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 50
file comparison...help needed.

Hello all,

Can anyone help me with this.
There are two files and I have to match the second file records with that of first and if matched, print the output in two fies, one containing the matched records and other containing the rest.

Here is the example.
Code:
File1 

"111",erter,"00000",    ,"567"
"gh6",erter,"00000",    ,"567"
"1t7",erter,"00000",    ,"yu7"
"yu8",erter,"00000",    ,"5h7"
--
--
--
Code:
file2

111
345
yu8
--
--
As can be seen 111 and yu8 matches with the first reord in file 1, so the whole row should be printed.

Output should be
Code:
file3 

"111",erter,"00000",    ,"567"
"yu8",erter,"00000",    ,"5h7"
--

--

and 

file4

"gh6",erter,"00000",    ,"567"
"1t7",erter,"00000",    ,"yu7"
---
---

-
Can anyone help me with this. Thanks.
  #2 (permalink)  
Old 05-13-2008
frozentin frozentin is offline
Registered User
  
 

Join Date: May 2008
Location: Vienna, VA + Bombay, India
Posts: 109
By looking at your 2 examples, why don't you;
[1] loop thru the contents of the 2nd file
[2] compare every individual line of the 2nd file with all the lines in the first
[3] print matched lines to file3
[4] After looping thru all the entries in file2, do a diff between file1 and file_matched
[5] parse the o/p of [4] to file4

Disclaimer: I couldn't script if my life depended on it, so can't really help you with that.

Last edited by frozentin; 05-13-2008 at 12:18 AM.. Reason: changed name of sample files
  #3 (permalink)  
Old 05-13-2008
er_ashu er_ashu is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 50
Quote:
Originally Posted by frozentin View Post
By looking at your 2 examples, why don't you;
[1] loop thru the contents of the 2nd file
[2] compare every individual line of the 2nd file with all the lines in the first
[3] print matched lines to file3
[4] After looping thru all the entries in file2, do a diff between file1 and file_matched
[5] parse the o/p of [4] to file4

Disclaimer: I couldn't script if my life depended on it, so can't really help you with that.
Thanks Frozentin but the issue here is that one of the file (file1 in this case ) has huge no of records and looping and comparing is taking a lot of time.

Is there any alternative way to do this with good performance.

Please advise.
  #4 (permalink)  
Old 05-13-2008
frozentin frozentin is offline
Registered User
  
 

Join Date: May 2008
Location: Vienna, VA + Bombay, India
Posts: 109
This suggestion depends on how big your second file is.

But, you could try to put all the entries of the 2nd file into a grep list and then loop thru the 1st file only once. This way you avoid multiple loops that I suggested in my last post.

One more way would be to attack the i/p file in chunks of say 1000 lines, and append o/p to file3/4.
  #5 (permalink)  
Old 05-15-2008
gmahesh2k gmahesh2k is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
Unhappy Script please

Can you please post the script for this as I am not getting to compare by using loop

Thnaks

mah
Sponsored Links
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 11:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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