]> git.nbdom.net Git - nb.git/commitdiff
bin/csv2human
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 27 Apr 2018 01:14:25 +0000 (02:14 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 27 Apr 2018 01:14:25 +0000 (02:14 +0100)
bin/csv2human
etc/profile.d/functions

index 6d7968fa5cafca1cc2c6854dfa44285a8f3feecf..fedf4d100f22734644fb03b2897ea41889c2d336 100755 (executable)
@@ -71,7 +71,16 @@ my $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10);
 print $sep_line;
 
 my $i = 0;
+my $count;
 while ($_ = shift @lines) {
+       if ($i == 0) {
+               $count = @$_;
+       } else {
+               for (my $j=@$_; $j<$count; $j++ ) {
+                       $_->[$j] = '';
+               }
+       }
+
        printf $format,@$_;
        print $sep_line if $Opt{header} and !$i++;
 }
index 010535e4959f613b8cf3ed9616a4ff1e70c993c5..36b73824544f3ef2ded9d912bb7bd81735266138 100644 (file)
@@ -556,72 +556,6 @@ exit $diff ? 0 : 1;
 
 }
 
-# NB 16.01.18 csv2human() {
-# NB 16.01.18          shell_help "Usage: $FUNCNAME [PERL_REGEXP --sep|-s (default: tab)] [--noheader|-nh]" "$@" && return;
-# NB 16.01.18          local sep noheader;
-# NB 16.01.18          sep='\t';
-# NB 16.01.18          noheader=0;
-# NB 16.01.18          local files=''
-# NB 16.01.18 
-# NB 16.01.18          while [ $# -gt 0 ]; do
-# NB 16.01.18 
-# NB 16.01.18                  if [ -e "$1" ]; then
-# NB 16.01.18                          files="$files $1"
-# NB 16.01.18                          shift
-# NB 16.01.18                          continue
-# NB 16.01.18                  fi
-# NB 16.01.18 
-# NB 16.01.18                  case "$1" in
-# NB 16.01.18                          --sep|-s)
-# NB 16.01.18                                          sep=$2;
-# NB 16.01.18                                          shift
-# NB 16.01.18                          ;;
-# NB 16.01.18                          --noheader|-nh)
-# NB 16.01.18                                          noheader=1
-# NB 16.01.18                          ;;
-# NB 16.01.18                          *)
-# NB 16.01.18                                          echo "Unknow option: $1 at $0!";
-# NB 16.01.18                                          return 1
-# NB 16.01.18                          ;;
-# NB 16.01.18 
-# NB 16.01.18                  esac
-# NB 16.01.18 
-# NB 16.01.18                  shift
-# NB 16.01.18 
-# NB 16.01.18          done
-# NB 16.01.18 
-# NB 16.01.18          [ -z "$@" ] || sep="$@";
-# NB 16.01.18 
-# NB 16.01.18          cat $files | perl -MEncode -F"$sep" -ane 'BEGIN {
-# NB 16.01.18  $noheader = shift @ARGV;
-# NB 16.01.18  @len = (); @lines = (); 
-# NB 16.01.18  binmode( STDOUT, "utf8:" );
-# NB 16.01.18 };
-# NB 16.01.18 for ($i=0;$i<@F;$i++) {
-# NB 16.01.18  chomp($F[$i]);
-# NB 16.01.18  $F[$i] =~ s/^\r//;
-# NB 16.01.18  $F[$i] = Encode::decode_utf8($F[$i]);
-# NB 16.01.18  $len[$i] = $l if ( $l = length($F[$i])) >= $len[$i];
-# NB 16.01.18 }
-# NB 16.01.18 push @lines, [@F];
-# NB 16.01.18 END {
-# NB 16.01.18  exit unless @lines;
-# NB 16.01.18  $i = 0;
-# NB 16.01.18  $t = -1;
-# NB 16.01.18  $tot = @lines - ($noheader ? 0 : 1);
-# NB 16.01.18  $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10);
-# NB 16.01.18  $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10);
-# NB 16.01.18  print $sep_line;
-# NB 16.01.18  while ($_ = shift @lines) {
-# NB 16.01.18          printf $format,@$_;
-# NB 16.01.18          print $sep_line if !$noheader and !$i++;
-# NB 16.01.18  }
-# NB 16.01.18  print $sep_line;
-# NB 16.01.18  print "$tot Records\n";
-# NB 16.01.18 }
-# NB 16.01.18 ' $noheader
-# NB 16.01.18 }
-
 mail_relay_closed() {
        shell_help "Usage: $FUNCNAME MAIL_SERVER" "$@" && return;
        local out=$(
@@ -957,3 +891,69 @@ html2pdf() {
 xml2csv() {
        xsltproc $NB_ROOT/lib/xslt/xml2csv.xslt $@
 }
+# NB 16.01.18 csv2h() {
+# NB 16.01.18          shell_help "Usage: $FUNCNAME [PERL_REGEXP --sep|-s (default: tab)] [--noheader|-nh]" "$@" && return;
+# NB 16.01.18          local sep noheader;
+# NB 16.01.18          sep='\t';
+# NB 16.01.18          noheader=0;
+# NB 16.01.18          local files=''
+# NB 16.01.18 
+# NB 16.01.18          while [ $# -gt 0 ]; do
+# NB 16.01.18 
+# NB 16.01.18                  if [ -e "$1" ]; then
+# NB 16.01.18                          files="$files $1"
+# NB 16.01.18                          shift
+# NB 16.01.18                          continue
+# NB 16.01.18                  fi
+# NB 16.01.18 
+# NB 16.01.18                  case "$1" in
+# NB 16.01.18                          --sep|-s)
+# NB 16.01.18                                          sep=$2;
+# NB 16.01.18                                          shift
+# NB 16.01.18                          ;;
+# NB 16.01.18                          --noheader|-nh)
+# NB 16.01.18                                          noheader=1
+# NB 16.01.18                          ;;
+# NB 16.01.18                          *)
+# NB 16.01.18                                          echo "Unknow option: $1 at $0!";
+# NB 16.01.18                                          return 1
+# NB 16.01.18                          ;;
+# NB 16.01.18 
+# NB 16.01.18                  esac
+# NB 16.01.18 
+# NB 16.01.18                  shift
+# NB 16.01.18 
+# NB 16.01.18          done
+# NB 16.01.18 
+# NB 16.01.18          [ -z "$@" ] || sep="$@";
+# NB 16.01.18 
+# NB 16.01.18          cat $files | perl -MEncode -F"$sep" -ane 'BEGIN {
+# NB 16.01.18  $noheader = shift @ARGV;
+# NB 16.01.18  @len = (); @lines = (); 
+# NB 16.01.18  binmode( STDOUT, "utf8:" );
+# NB 16.01.18 };
+# NB 16.01.18 for ($i=0;$i<@F;$i++) {
+# NB 16.01.18  chomp($F[$i]);
+# NB 16.01.18  $F[$i] =~ s/^\r//;
+# NB 16.01.18  $F[$i] = Encode::decode_utf8($F[$i]);
+# NB 16.01.18  $len[$i] = $l if ( $l = length($F[$i])) >= $len[$i];
+# NB 16.01.18 }
+# NB 16.01.18 push @lines, [@F];
+# NB 16.01.18 END {
+# NB 16.01.18  exit unless @lines;
+# NB 16.01.18  $i = 0;
+# NB 16.01.18  $t = -1;
+# NB 16.01.18  $tot = @lines - ($noheader ? 0 : 1);
+# NB 16.01.18  $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10);
+# NB 16.01.18  $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10);
+# NB 16.01.18  print $sep_line;
+# NB 16.01.18  while ($_ = shift @lines) {
+# NB 16.01.18          printf $format,@$_;
+# NB 16.01.18          print $sep_line if !$noheader and !$i++;
+# NB 16.01.18  }
+# NB 16.01.18  print $sep_line;
+# NB 16.01.18  print "$tot Records\n";
+# NB 16.01.18 }
+# NB 16.01.18 ' $noheader
+# NB 16.01.18 }
+