From 9d0a4bee3ae115f9ddb6db4cac01bb80b295ff04 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 20 Apr 2023 02:56:15 +0200 Subject: [PATCH] option --format --- bin/csv2human | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/csv2human b/bin/csv2human index 93312e9e..5eb27e87 100755 --- a/bin/csv2human +++ b/bin/csv2human @@ -47,11 +47,10 @@ my @lines = (); while (<>) { - my @F = split(/$Opt{sep}/); + my @F = $Opt{format} ? split(/\s*$Opt{sep}\s*/) : split(/$Opt{sep}/); for (my $i=0;$i<@F;$i++) { chomp($F[$i]); - #$F[$i] =~ s/^\r//; $F[$i] = Encode::decode_utf8($F[$i]); my $l; $len[$i] = $l if ( $l = length($F[$i]) ) >= ($len[$i] || 0); @@ -62,15 +61,20 @@ while (<>) { exit unless @lines; -# NB 11.07.19 Bug Wrong ! my $tot = @lines - ($Opt{header} ? 0 : 1); my $tot = @lines - ($Opt{header} ? 1 : 0); my $t = -1; -my $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10); +my $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10); my $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10); -print $sep_line; +if ($Opt{format}) { + my $sep = " ".$Opt{sep}." "; + $format = join($sep,map {$t+=$_+length($sep); "\%-".$_."s"} @len).chr(10); + $sep_line = ""; +} + +print $sep_line; my $i = 0; my $count; while (my $line = shift @lines) @@ -210,6 +214,7 @@ Description! -option[header|h!] Print or not header separotor after first row -option[sep|s=s] Separtor + -option[format|f!] Only format according to option --sep. Usefull for coding -option[verbose|v+] Verbose mode: increase the verbosity level. -option[debug+] Debug mode: increase the verbosity level. -option[version|V] Print version (default: $VERSION) -- 2.47.3