I have a perl script I would like to migrate to awk. It's quite simple - it copies a file and amends the footer to reflect the number of records (line count so far minus one for the header). In perl it looks like
I'm not looking for a full solution but I'd like some hints on how to identify the last line so as to treat it differently.
Thanks
On the internet no one knows you're a dog
Columb Healy
Code:
#!/usr/bin/perl -w
use strict;
$#ARGV == 2 or die "Invalid agument count\n";
open IFH, $ARGV[0] or die "Unable to open $ARGV[0] for reading\n";
open OFH, ">$ARGV[1]" or die "Unable to open $ARGV[1] for writing\n";
open UFH, ">$ARGV[2]" or die "Unable to open $ARGV[2] for writing\n";
my $count = -1;
while (<IFH>)
{
eof ( IFH ) or $count++,(print OFH), next;
my @bits = split /\|/;
$bits[1] = sprintf "%9.9d", $count;
print OFH +(join '|', @bits), "\n";
printf UFH "%9.9d\n", $count;
}
close IFH;
close OFH;
close UFH;
Thanks
On the internet no one knows you're a dog
Columb Healy