-
Notifications
You must be signed in to change notification settings - Fork 2
/
table2tab.pl
executable file
·76 lines (61 loc) · 1.27 KB
/
table2tab.pl
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
use warnings;
use strict;
use autodie;
use Data::Dump qw(dump);
# parse formatted dell output with
# --- ------- -----
# to tab delimited lines
my $debug = $ENV{DEBUG} || 0;
my $line_regex;
my @line_regex_short;
my @lines;
while(<>) {
chomp;
if ( /^--+/ ) {
$line_regex = $_;
$line_regex =~ s/\s+$//;
$line_regex =~ s/-/./g;
$line_regex =~ s/^/(/g;
$line_regex =~ s/(\s+)/)$1(/g;
$line_regex =~ s/$/)/;
my $l = $line_regex;
while ( $l ) {
my $l_w = $l;
$l_w =~ s/\.+\)$/.+)/;
push @line_regex_short, $l_w;
$l =~ s/\s*\(\.+\)$//;
warn "# [$l]\n" if $debug;
}
print STDERR "$_\n$line_regex\n", dump( @line_regex_short ), "\n" if $debug;
next;
}
my @v;
if ( defined($line_regex) ) {
my @v = ( /$line_regex/ );
foreach my $regex ( @line_regex_short ) {
last if @v;
@v = ( /$regex/ );
}
if ( @v ) {
@v = map { s/^\s+//; s/\s+$//; $_ } @v;
warn "# v = ",dump(@v) if $debug;
if ( $v[0] eq '' ) {
foreach my $i ( 1 .. $#v ) {
next if $v[$i] eq '';
$lines[$#lines]->[$i] .= $v[$i];
}
} else {
push @lines, [ @v ];
}
} else {
push @lines, [ $_ ];
warn "SKIP [$_]\n" if $debug;
}
} else {
push @lines, [ $_ ];
}
}
foreach my $a ( @lines ) {
print join("\t", @$a), "\n"
}