![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| compare 2 files.. | amon | Shell Programming and Scripting | 8 | 06-23-2008 07:34 AM |
| compare two files | charandevu | Shell Programming and Scripting | 7 | 03-30-2008 12:20 PM |
| compare two txt files | space13 | Shell Programming and Scripting | 8 | 09-22-2006 06:40 AM |
| compare files and beyond | MizzGail | UNIX for Dummies Questions & Answers | 2 | 04-25-2003 10:34 AM |
| compare files | ingunix | UNIX for Dummies Questions & Answers | 3 | 05-24-2001 08:44 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Code:
#! /opt/third-party/bin/perl
open(FILE, "<", secondfile) || die ("Unable to open secondfile. <$!>\n");
while( <FILE> ) {
chomp;
@split_arr = split(/ /, $_);
my $dump;
for( my $i = 1; $i <= $#split_arr; $i++ ) {
$dump .= ( $split_arr[$i] . ":");
}
$dump =~ s/:$//;
$fileHash{$split_arr[0]} = $dump;
}
close(FILE);
open(FILE, "<", firstfile) || die ("Unable to open firstfile. <$!>\n");
while( <FILE> ) {
chomp;
@first_arr = split(/ /, $_);
print "$first_arr[0] ";
foreach my $key ( keys %fileHash ) {
@second_arr = split(/:/, $fileHash{$key});
for($i = 0; $i <= $#second_arr; $i++ ) {
$set = 0;
for( $j = 1; $j <= $#first_arr; $j++ ) {
if( $first_arr[$j] =~ $second_arr[$i] ) {
$set = 1;
last;
}
}
last if( $set == 0 && $#first_arr > 1 )
}
print "$key " if( $set == 1 )
}
print "\n";
}
close(FILE);
exit 0
Quote:
Its working fine but got one problem. I think I mentioned it on the thread that it's looking for a file pattern not the exact word. Please see below: File1 AAABB370 MI_AP MI_RC MI_REC_DUP VIEW AAABB371 VIEW AAABB372 MI_UNIT VIEW AAABB373 REQUEST APPROVE INQUIRE AAABB374 REQUEST APPROVE MI_AP MI_RC MI_REC VIEW File2 role1 MI_RC MI_REC role2 MI_AP MI_REC role3 VIEW role4 VIEW MI_UNIT role5 REQUEST APPROVE INQUIRE role6 REQUEST Code Output: AAABB370 role1 role3 role2 AAABB371 role3 AAABB372 role3 role4 AAABB373 role6 role5 AAABB374 role1 role3 role6 role2 Needed Output: AAABB370 role3 role2 AAABB371 role3 AAABB372 role3 role4 AAABB373 role6 role5 AAABB374 role3 role6 role2 Last edited by kharen11; 03-13-2007 at 06:56 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
So, the difference is in these two, Code:
AAABB370 role1 role3 role2 AAABB374 role1 role3 role6 role2 when you say the needed output should be AAABB370 role3 role2 and not AAABB370 role1 role2 role3 ... how is role2 matched with AAABB370 then ? .... ' role2 ' should not be displayed with AAABB370 as per your statement. Either of the case pattern is matched MI_REC_DUP is matched with MI_REC with role2 T Sorry, If I havent understood it correctly! I believe am getting the output as you had said before. If not clear, please post with clarifications ! |
|
|||
|
Quote:
Opps!! sorry.. The output should be: AAABB370 role3 (without the role2) AAABB371 role3 AAABB372 role3 role4 AAABB373 role6 role5 AAABB374 role1 role2 role3 role6 For clarification: AAABB370 cannot have role1 and role2 because his role is MI_REC_DUP and not MI_REC. AAABB374 should have role1 and role2 because it has tha exact name of MI_REC. Hope its clearer this time.. Last edited by kharen11; 03-13-2007 at 09:42 PM. |
|
|||
|
This time its very clear!
Thats clearly my mistake change the following line from Quote:
Code:
if( $first_arr[$j] eq $second_arr[$i] ) {
Code:
AAABB370 role3 AAABB371 role3 AAABB372 role3 role4 AAABB373 role5 role6 AAABB374 role6 role1 role2 role3 |
|
|||
|
Quote:
Perfect! That works wonders!!!! Thank you so much for the BIG help |
|||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|