[RndTbl] Looking for some AWK magic
Trevor Cordes
trevor at tecnopolis.ca
Sun Sep 24 18:20:33 CDT 2017
On 2017-09-21 Wyatt Zacharias wrote:
> So I've got a storage appliance that I'm trying to generate a growth
> chart on, but the output format of the statistics is not in a usable
> format.
>
> The output looks like this, with each day of the week in a column,
> and then 6 rows of data underneath, and then it repeats.
> -2- -3- -4- -5- -6- -7- -8-
> 5827.1 6865.6 3551.2 4649.5 4006.6 15803.5 10305.0
> 199.4 353.4 175.9 200.7 172.5 584.0 554.2
Like John said, this is perfect for perl. And perl is available on
every system, even HPUX, and it doesn't even need to be a modern perl.
You've probably already solved it, but I'll throw a perl solution out
there for kicks:
# build a sane data structure of what you want
while (<>) {
next if /^\s*$/;
$redates='\s+-(\d+)-'x7; # build the regex
@dates=/$redates/,$stanza++,next if /$redates/;
$renums='\s*([0-9.x]+)'x7;
if (@nums=/$renums/) {
foreach $i (0..6) {
push(@{$table{sprintf "%02d%02d",$stanza,$dates[$i]}},$nums[$i]);
}
}
}
# now do what you want on the data
foreach $stanzadate (sort keys %table) {
print "$stanzadate: ".join(' , ',@{$table{$stanzadate}})."\n";
# do something with it
# foreach $entry (@{$table{$stanzadate}}) { $sum+=$entry... whatever }
}
It was a little more complicated because the dates can (and do) repeat,
so the hash key I made a combination key so it still sorts nicely.
I can also see a way to do it in plain bash with head and cut, and
maybe paste? But my bash looping syntax skillz stink, so I leave that
as an exercise.
More information about the Roundtable
mailing list