Actually, you should probably step through the file in a loop rather than your current approach...(Late night code warning remains in force but this is closer to working than the approach above )
#!/usr/bin/perl
open (my $data, '<', $ARGV[0]);
while (<$data>){
$record{$1}=$2 if (/(\S+)\s*:\s*(.+)$/);
}
if ((/^\s*$/) && ($record{Filesname} ne '')){
print join('|',@record{"Filename","Record","Unzipped Bytes"}),"\n";
$record{Filename}='';
}
Hi dotran,
Note that vgersh99 suggested using the awk utility (not the non-existent BEGIN utility).
And, awk is perfectly capable of reading files without creating a pipeline using cat to double the number of processes running and triple the number of bytes read and written to read your input file.
Please look more closely at what vgersh99 suggested and try what he suggested.
vgersh99's proposal does work on my (Free)BSD system, but not quite on my linux mawk , as the line feeds are not used as field separators there. Try using FS="[:\n]" instead.
Thanks Mr RudiC & Don. I still get syntax somehow
/staging/dotran :cat abctest.ksh
#!/bin/ksh
awk '
BEGIN {RS=""
FS="[:\n]"
OFS="|"
for (i=split("Filename|Records|Unzipped Bytes ", t, "|"); i; i--) namesA[t]=i
}
{for(i=1; i<=NF;i=i+2)
if ($i in namesA)
printf("%s", (namesA[$i]==1)?$(i+1):OFS $(i+1))
print ""
}
' abc.txt
/staging/dotran :./abctest.ksh
awk: syntax error near line 8
awk: illegal statement near line 8
awk: syntax error near line 9
awk: illegal statement near line 9
I got this thread confused with a different thread where the OS was specified to be a Linux distribution. This thread doesn't specify the OS, so I should have included the warning line.