1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/perl -l
use strict;
use vars qw($VERSION);
use vars qw($t $data @data $re);
use vars qw(@f $help $separator);
$VERSION = "1.00";
use Getopt::Long;
use Text::TabularDisplay;
GetOptions("f=s" => \@f,
"h!" => \$help,
"s=s" => \$separator);
if (defined $help) {
print usage();
exit 0;
}
$separator = '\s' unless defined $separator;
$re = qr($separator);
$t = Text::TabularDisplay->new;
chomp($data = <STDIN>);
@data = split $re, $data;
@f = split /,/, $f[0] if (@f == 1);
@f = (0 .. $#data) unless (@f);
$t->columns(@data[@f]);
while (defined($data = <STDIN>)) {
chomp $data;
@data = split $re, $data;
$t->add(@data[@f])
}
print $t->render;
sub usage {
require File::Basename;
my $prog = File::Basename::basename($0);
return <<"USAGE";
$prog v.$VERSION
$prog [-s \$separator] [-f fields] < data
data should be a series of \$separator-delimited lines,
which will be displayed in a table, of which the fields
defined by -f will be displayed (defaults to all fields).
USAGE
}
|