The UNIX and Linux Forums  


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
Very urgent :- How to compare string using if statement jisha Shell Programming and Scripting 1 01-14-2008 03:41 AM
Urgent Help: Perl Hash compare jamie123 Shell Programming and Scripting 10 01-04-2008 03:09 AM
Compare Data in the same file lweegp UNIX for Dummies Questions & Answers 1 10-17-2005 03:32 AM
Compare data files ithomp Shell Programming and Scripting 1 06-15-2004 11:08 AM
compare data bensky UNIX for Dummies Questions & Answers 3 10-10-2003 06:17 AM

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 02-27-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
Exclamation [urgent need help]compare data

hi all,

very need help urgently

i have a problem compare 2 files from solaris, the 2 files its shown below:

data1.log :
6512345678 6512345677 20070131 073824 420
6511111111 6522222222 20070131 103747 87
6522222222 6233333333 20070131 120855 31
6533333333 6244444444 20070131 121006 48


data2.log:
P 055006.410 20070131 073824 6511111111 510000000000000 6511111111 00 0 000 012 0 0 0
P 055006.530 20070131 103747 6522222222 510000000000000 6522222222 00 0 000 003 0 0 0
P 055006.531 20070131 120855 6533333333 510000000000000 6533333333 00 0 000 004 0 0 0
P 055006.590 20070131 121006 11111111111 510000000000000 11111111111 00 0 000 003 0 0 0
P 055006.650 20070131 133333 222222222 510000000000000 22222222222 00 0 000 003 0 0 0

compare from data1.log to data2.log on column 1, column 3 and column 4 for data1.log compare with column 3, column 4 and column 7 for data2.log
if match and write it to files.

expected output is:

success :
6511111111 6522222222 20070131 103747 87
P 055006.410 20070131 073824 6511111111 510000000000000 6511111111 00 0 000 012 0 0 0


6522222222 6233333333 20070131 120855 31
P 055006.530 20070131 103747 6522222222 510000000000000 6522222222 00 0 000 003 0 0 0


6533333333 6244444444 20070131 121006 48
P 055006.531 20070131 120855 6533333333 510000000000000 6533333333 00 0 000 004 0 0 0


fail :
6512345678 6512345677 20070131 073824 420


fail output if data on data1.log not found in data2.log

please need advices with script or using syntax command


thank you so much

regards,

bucci
  #2 (permalink)  
Old 02-27-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
I find column 1, column 3 of data1 match with col 7 and col 3 of data2.

Code:
awk ' BEGIN { while( getline < "data1.log" ) { str[$1" "$3]=$0 } }
{ 
if ( str[$7" "$3] !~ /^ *$/ ) 
{ 
	print str[$7" "$3] "\n" $0 "\n\n" > "success"
	delete str[$7" "$3];
}
} 
END { 
for( key in str) {
if ( str[key] !~ /^ *$/ ) 
	print str[key] >"fail"
} }
' data2.log

  #3 (permalink)  
Old 02-27-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
hi anbu,

thank you so much for your attention



Quote:
Originally Posted by anbu23
I find column 1, column 3 of data1 match with col 7 and col 3 of data2.

Code:
awk ' BEGIN { while( getline < "data1.log" ) { str[$1" "$3]=$0 } }
{ 
if ( str[$7" "$3] !~ /^ *$/ ) 
{ 
	print str[$7" "$3] "\n" $0 "\n\n" > "success"
	delete str[$7" "$3];
}
} 
END { 
for( key in str) {
if ( str[key] !~ /^ *$/ ) 
	print str[key] >"fail"
} }
' data2.log

Last edited by bucci; 02-28-2007 at 12:27 AM..
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:52 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