8 td-trans-fixcol - Transform a table-looking text, aligned to fixed columns by spaces, into tabular data.
12 First line is the header consisting of the column names.
13 Each field's text must start in the same terminal column as the column name.
19 =item -m, --min-column-spacing I<NUM>
21 Minimum spacing between columns.
23 This allows the input data to have column names with single spaces.
29 arp -n | td-trans-fixcol
35 $OptMinColumnSpacing = 2;
37 'h|header' => sub { $OptShowHeader = 1; },
38 'H|no-header' => sub { $OptShowHeader = 0; },
39 'm|min-column-spacing=i' => \
$OptMinColumnSpacing,
42 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
43 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
51 $headline =~ s/\s*$//;
52 while($headline =~ /^(.+?)([ ]{$OptMinColumnSpacing,}|$)/)
54 my ($colname, $spaces) = ($1, $2);
55 my $width = length($colname.$spaces);
58 start
=> $chars_eaten,
61 $chars_eaten += $width;
65 # last column is undefinitely wide
66 $Column[$#Column]->{width} = undef if scalar @Column;
69 if($OptShowHeader and @Column)
71 print join($FS, map {$_->{name}} @Column).$RS;
74 while(my $line = <STDIN>)
79 for my $idx (0..$#Column)
81 my $field = substr $line, $Column[$idx]->{start}, $Column[$idx]->{width} || length $line;
86 print join($FS, @Fields).$RS;