App-Bin4TSV
view release on metacpan or search on metacpan
scripts/colorplus view on Meta::CPAN
0.31 (2018-07-10)
=head1 SYNOPSIS
colorplus [-0] [-n N|-3|-4] [-c colorname] [-e N[,N[,N..]]] [-l N] [-s REGEX] [-t N] [-/ char]
colorplus [--help [opt|en]] [--version]
=head1 DESCRIPTION
Put colors (ASCII color escape sequnces) parts on text data such as numerical parts,
columns cyclically, text matching specific regular expressions. Useful to look around
CSV/TSV files with a pager LESS (less -R).
=head1 OPTIONS
=over 4
=item B<-0>
Remove colors (remove all the ASCII color escape sequences).
=item B<-n> N
Put colors on numerical characters. Every neighboring N digits from the bottom of a numerical
character sequence has a same color. Cyan, green, yellow are used to colorize.
=item B<-3>
Same as the specification B<-n 3>.
=item B<-4>
Same as the specification B<-n 4>.
=item B<-c> colorname
Speficy the colorname. It can be "blue", "red", "yellow", and also "on_while", "underline" and so on.
See the ASCII color escape sequences.
=item B<-e> N,N,...
Any operation by "colorplus" is exemplified on the lines specified by the number(s) beginning from 1.
-0 is also cancelled on the specified lines, thus in this case, the input color on the specified line
will survive.
=item B<-l> N
One line from every N lines are colored. The default color : "on_blue".
scripts/csv2tsv view on Meta::CPAN
sub main ( ) {
binmode * STDOUT , ":utf8" ; # Necessry because Text::CSV_XS decodes UTF8 input.
binmode * STDERR , ":utf8" ; # Necessry because Text::CSV_XS decodes UTF8 input.
my $linepos = 1 ; # CSV ã§èªã¿è¾¼ãã§ããã®ã§ã$. ã¯2以ä¸å¢ãããã¨ããããèªã¿åã度ã«ã $linepos ãã $. è¡ç®ã¾ã§ã¨èªèããããã
my %cols ; # ä½åã®åãä½è¡ãæã£ã¦ãããã表ãã3åã®è¡ã120è¡åå¨ããããªã©ã表ãã
our $csv = Text::CSV_XS -> new ( { binary => 1 , sep_char => $o{s} , auto_diag => 1 } ) ; # if binary => 0 then when "\n" is included in a cell it cause trouble.
push my @trans , grep {$_} do { [ "\t" , $o{t} ] if defined $o{t} } , do { [ "\n" , $o{n} ] if defined $o{n} } ; # æååç½®æã®æå®ã
my @warnstr ; # è¦åå¯¾è±¡ã®æååãæ¹è¡ãã¿ãæåãªã©
my @escape ; # ã¨ã¹ã±ã¼ãå¯¾è±¡ã®æåå
unless ($o{Q}) {
push @warnstr , $o{t} if defined $o{t} ;
push @warnstr , $o{n} if defined $o{n} ;
@warnstr = grep { $_ ne '' } @warnstr ;
@escape = map { quotemeta $_ } @warnstr ; # ãã®æç¹ã§ -vã®ãã®ã¯ã¯ãã£ã¦ããªã
push @warnstr , "\t" if $o{v} || ! defined $o{t} ;
push @warnstr , "\n" if $o{v} || ! defined $o{n} ;
}
# å
¥åãèªåããå¦çãã¦åºåã
my $posV = 0 ; # åºåä¸ã®ç¸¦æ¹åã®ä½ç½®ã表ã
while ( my $x = $csv -> getline( *ARGV ) ) { # 次è¡ä»¥ä¸ãèªããã¨â
# *ARGVã¯Old(er) support 㨠perldoc Text::CSV_XSã«è¨è¼ãããå°æ¥ãµãã¼ããããªãããã
# geline ã§ããã¨ã©ã¼ãèµ·ããããªãã ? <--- - -
do { $alarmF = 0 ; alarm 0 } if $alarmF ;
$posV ++ ;
$cols{ @$x } ++ ; # ãã®è¡ã¯ãåãä½åæã£ã¦ãããã®æ°ããï¼å¾ã§ï¼ä½åã®è¡ãä½åã®åãæã£ã¦ãããæ
å ±è¡¨ç¤ºãããããã«ããã
my $posH = 0 ; # åºåä¸ã®ã»ã«ã®æ°´å¹³ä½ç½®ã表ãã
for my $cell ( @$x ) {
$posH ++ ;
warnprint ( $cell , \@warnstr, [ $linepos , $posV , $posH ] ) unless $o{Q} ; # è¦æ³¨ææååã«å¯¾ãã¦ãè¦åã表示ããã
$cell =~ s/(?=$_)/$o{e}/g for @escape ; # ã¨ã¹ã±ã¼ããã /
$cell =~ s/$trans[$_]->[0]/$trans[$_]->[1]/g for 0 .. $#trans ; # -tã¨-nã®å¦çãå ããã
}
# åºåå¦ç
print join ( "\t", @$x ) . "\n" ;
print "\n" if $o{2} ; # # åºååè¡ã®éã«ç©ºè¡ãæ¿å
¥ããå ´åã®å¦ç
$linepos = $. + 1 ; # <- å
¥åã®ä½è¡ç®ãæ¹è¡åºåãã§æ°ãã $. ã« +1 ãã¦ãããtricky!
}
$csv->eof; # <-- - å¿
è¦ã?
& info ( $. , \%cols ) unless $o{Q} ;
return 1 ;
( run in 0.381 second using v1.01-cache-2.11-cpan-c21f80fb71c )