![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Merge text files while combining the multiple header/trailer records into one each. | oordonez | Shell Programming and Scripting | 4 | 11-17-2008 11:06 PM |
| What is your age? (Part 2) | Perderabo | What's on Your Mind? | 37 | 07-20-2007 12:27 PM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 12:15 PM |
| Help comparing 2 files to find deleted records | eja | UNIX for Dummies Questions & Answers | 2 | 04-03-2007 08:53 AM |
| How to extract duplicate records with associated header record | run_eim | UNIX for Dummies Questions & Answers | 17 | 01-16-2007 11:46 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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): Code:
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 Code:
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";
}
|
| Sponsored Links | ||
|
|