Trying to combine first 2 lines of a perl array as shown below:
time |cpu |mem|
stamp|util|util |
to:
time_stamp|cpu_util|mem_util|
Using perl as this needs to work on both windows and linux
Trying to combine first 2 lines of a perl array as shown below:
time |cpu |mem|
stamp|util|util |
to:
time_stamp|cpu_util|mem_util|
Using perl as this needs to work on both windows and linux
Check this out:
> cat cpu.txt
time|cpu|mem|
stamp|util|util|
> perl -F'/\|/' -lane ' { push(@line,@F)} END { for($i=0;$i<3;$i++) { printf("%s", "${line[$i]}_${line[$i+3]}|") }print}' cpu.>
time_stamp|cpu_util|mem_util|
>
For a newbie, this is what I came up with, but I think there is probably a more elegant solution.
@netifdata_array = ( Time|Interface | Network| In| Out|,
Stamp|Name | Speed| KB Rate| KB Rate|);
my (@line1, @line2, @line3);
my $ct;
@line1 = split(/\s*\|\s*/, @netifdata_array[0]);
@line1 = grep(s/\s*//g, @line1);
@line2 = split(/\s*\|\s*/, @netifdata_array[1]);
@line2 = grep(s/\s*//g, @line2);
$ct = $ct + scalar(@line2);
for (my $i = 0; $i < $ct; $i++)
{
push (@line3, $line1[$i], $line2[$i], "|");
}
print @line3,"\n";
output: TimeStamp|InterfaceName|NetworkSpeed|InKBRate|OutKBRate|