merge git log from multiple repositories by date
[dell-switch] / table2tab.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use autodie;
5
6 use Data::Dump qw(dump);
7
8 # parse formatted dell output with
9 # --- ------- -----
10 # to tab delimited lines
11
12 my $debug = $ENV{DEBUG} || 0;
13
14 my $line_regex;
15 my @line_regex_short;
16 my @lines;
17
18 while(<>) {
19         chomp;
20
21         if ( /^--+/ ) {
22                 $line_regex = $_;
23                 $line_regex =~ s/\s+$//;
24                 $line_regex =~ s/-/./g;
25                 $line_regex =~ s/^/(/g;
26                 $line_regex =~ s/(\s+)/)$1(/g;
27                 $line_regex =~ s/$/)/;
28
29                 my $l = $line_regex;
30                 while ( $l ) {
31                         my $l_w = $l;
32                         $l_w =~ s/\.+\)$/.+)/;
33                         push @line_regex_short, $l_w;
34                         $l =~ s/\s*\(\.+\)$//;
35                         warn "# [$l]\n" if $debug;
36                 }
37
38                 print STDERR "$_\n$line_regex\n", dump( @line_regex_short ), "\n" if $debug;
39                 next;
40         }
41
42         my @v;
43
44         if ( defined($line_regex) ) {
45                 my @v = ( /$line_regex/ );
46
47                 foreach my $regex ( @line_regex_short ) {
48                         last if @v;
49                         @v = ( /$regex/ );
50                 }
51
52                 if ( @v ) {
53                         @v = map { s/^\s+//; s/\s+$//; $_ } @v;
54                         warn "# v = ",dump(@v) if $debug;
55                         if ( $v[0] eq '' ) {
56
57                                 foreach my $i ( 1 .. $#v ) {
58                                         next if $v[$i] eq '';
59                                         $lines[$#lines]->[$i] .= $v[$i];
60                                 }
61
62                         } else {
63                                 push @lines, [ @v ];
64                         }
65                 } else {
66                         push @lines, [ $_ ];
67                         warn "SKIP [$_]\n" if $debug;
68                 }
69         } else {
70                 push @lines, [ $_ ];
71         }
72 }
73
74 foreach my $a ( @lines ) {
75         print join("\t", @$a), "\n" 
76 }