I need to list the file and the filename comes from the file ListOfFile.txt.
Basicly I have a filename "ListOfFile.txt" and it contain
Example of ListOfFile.txt
/home/Dave/Program/Tran1.P
/home/Dave/Program/Tran2.P
/home/Dave/Program/Tran3.P
/home/Dave/Program/Tran4.P
/home/Dave/Program/Tran5.P
Each file contain the same format on the first 2 lines about it's version.
I need to read the data from thesecond line column 3
Example of Tran1.P
/****************************
01122008 /home/Dave/Program/Tran1.P 10.05
****************************/
After I get the data from second line column 3 (10.05), I need to compare this data to the same filename that I found from file mapVersion.txt
Example of mapVersion.txt
Tran001.P|3.4
Tran020.P|4.2
Tran1.P|10.05
Tran12.P|4.11
Tran2.P|3.0
Tran3.P|10.5
Tran3A.P|12.3
Tran4.P|4.1
Tran5.P|1.2
I want to know if it's the same or not.
I know how to write script with ksh but I like to use awk to do this because I think it's faster than while loop.
Notice that if the input files are large and you have GNU awk, including nextfile after the print statement in the if block (you should add another pair of braces too) will significantly improve the performance of the script.
#!/usr/bin/perl
open FH,"<mapVersion.txt";
while(<FH>){
chomp;
my @tmp=split("[|]",$_);
$hash{$tmp[0]}=$tmp[1];
}
close FH;
# above put <mapVersion.txt> content into a hash
open FH,"<ListOfFile.txt";
while(<FH>){
chomp;
if (not exists $hash{$_}){
print "No need to check $_\n";
next;
}
else{
open TFH,"c.sh $_|"; #c.sh is just get our desired value of certain file's second line my $tmp=<TFH>;
if ($tmp != $hash{$_}){
print "Not match for $_ [$hash{$_} -- $tmp]\n";
}
else{
print "Match for $_\n";
}
close TFH;
}
}