comparing part of header with part of detailed records.

Hi there,

I am lil confused with the following issue.

I have a File, which has the following header: IMSHRATE_043008_101016

a sample detailed record is :9820101 A982005000CAVG030108000000000000010169000MAR 2008
9820102 MAR 2008 D030108

I need to compare the part of Header (it is highlighted in Red Font and its a DDMMYY format ) with the Part of Detailed record (its highlighted in Yellow font and its also DDMMYY format).

The problem is there are thousands of such detailed records (on an average 50000 records) in a single file. Can anyone help me in comparing those 'part of header' with the 'part of detailed record' highlightened in Red and Yellow font in above example ?

Regards,
Cmaroju

Hi ,

Is the yellow highlighted section is fixed in all your detail lines?

anyway , below perl may help you a little

input(a.txt):

IMSHRATE_043008_101016
9820101 A982005000CAVG 030108 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
9820101 A982005000CAVG 030109 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
9820101 A982005000CAVG 043008 000000000000010169000MAR 2008 9820102 MAR 2008 D030108

output:

MSHRATE_043008_101016
9820101 A982005000CAVG 030108 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
Smaller than header
9820101 A982005000CAVG 030109 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
Bigger than header
9820101 A982005000CAVG 043008 000000000000010169000MAR 2008 9820102 MAR 2008 D030108
Equal with header

code:

open FH,"<a.txt" or die "Can not open file\n";
my @arr=<FH>;
close FH;
$arr[0]=~m/(.*)_([0-9][0-9])([0-9][0-9])([0-9][0-9])_(.*)/;
$header=$4.$2.$3;
print $arr[0];
for($i=1;$i<=$#arr;$i++){
	my @temp=split(" ",$arr[$i]);
	$temp[2]=~m/([0-9][0-9])([0-9][0-9])([0-9][0-9])/;
	my $body=$3.$1.$2;
	print $arr[$i],($body>$header)?"Bigger than header\n":($body==$header)?"Equal with header\n":"Smaller than header\n";
}