-xcsv command to postprocess and organize many commands into csv format

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9240 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2011-04-07 18:27:46 +00:00
parent faf7e07a8c
commit f73ee11fd4

50
xCAT-client/bin/xcsv Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
use lib "$::XCATROOT/lib/perl";
use Data::Dumper;
use xCAT::Client;
my %columns;
use strict;
my %output;
while (<STDIN>) {
my $node;
my $output;
if (/:/) {
($node,$output) = split /:/,$_,2;
} else {
$node= "UNKNOWN";
$output = $_;
}
my $colname;
if ($output =~ /:/) {
($colname,$output) = split /:/,$output,2;
} else {
$colname = "UNKNOWN";
}
$colname =~ s/^ *//;
$output =~ s/^ //;
$output =~ s/\n//;
$output{$node}->{$colname}.=$output;
$columns{$colname}=1;
}
my @columns;
foreach (keys %columns) { #create,preserv ordered list of columns
push @columns, $_;
}
print join(',',"node",@columns)."\n";
my $nodes;
sub fillerup {
my $response = shift;
if ($response->{data}->[0]) {
$nodes = $response->{data}->[0];
}
}
foreach my $node (keys %output) {
my @output=($node);
foreach (@columns) {
push @output,$output{$node}->{$_};
}
print join(",",@output)."\n";
}