![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
Oops!
I should have made it clear! 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 + 1; $i++ ) {
$dump .= $split_arr[$i];
}
$fileHash{$split_arr[0]} = $dump;
}
close(FILE);
open(FILE, "<", firstfile) || die ("Unable to open firstfile. <$!>\n");
while( <FILE> ) {
chomp;
@split_arr = split(/ /, $_);
my $dump;
for( my $i = 1; $i < $#split_arr + 1; $i++ ) {
$dump .= $split_arr[$i];
}
print "$split_arr[0] ";
foreach my $key ( keys %fileHash ) {
if( $fileHash{$key} =~ m/$dump/ ) {
print "$key ";
}
}
print "\n";
}
close(FILE);
exit 0
|
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
Wow! You're a genius! It worked! It will save me lots of time in doing my work.
Thanks a lot! |
|
#10
|
|||
|
|||
|
Quote:
I find some minor problem on the code. It should search for the exact file pattern. In my example below: record1 mary MI_AP anne MI_RC record2 role1 MI_AP_REC role2 MI_AP MI_RC output of the current code: mary role1 role2 anne role2 Is it possible that it should only search for exact word so the output will be (below) ..? mary role2 anne role2 |
|
#11
|
|||
|
|||
|
Quote:
Code:
if( $fileHash{$key} =~ $dump ) {
|
|
#12
|
|||
|
|||
|
Quote:
|
|
#13
|
|||
|
|||
|
run the below as such and let us know the results
I have modified the code 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;
@split_arr = split(/ /, $_);
my $dump;
for( my $i = 1; $i < $#split_arr + 1; $i++ ) {
$dump .= $split_arr[$i];
}
print "$split_arr[0] ";
foreach my $key ( keys %fileHash ) {
@diff_arr = split(/:/, $fileHash{$key});
for( my $i = 0; $i <= $#diff_arr; $i++ ) {
if( $dump =~ $diff_arr[$i] ) {
print "$key ";
}
}
}
print "\n";
}
close(FILE);
exit 0
|
|
#14
|
|||
|
|||
|
Yes it works!!! Thank you so much.
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|