App-Bin4TSV
view release on metacpan or search on metacpan
scripts/csv2tsv view on Meta::CPAN
s/\Q'=script='\E/$Script/gi ;
s/\Q'=bin='\E/$Bin/gi ;
if ( s/^=head1\b\s*// .. s/^=cut\b\s*// ) {
if ( s/^=begin\s+$jd\b\s*// .. s/^=end\s+$jd\b\s*// xor $flagE ) {
print $_ if ! opt || m/^\s+\-/ ;
}
}
}
close $FH ;
exit 0 ;
}
=encoding utf8
=head1 NAME
csv2tsv
=head1 VERSION
0.55 (2018-07-09 Mon)
=head1 SYNOPSIS
csv2tsv [B<-t> str] [B<-n> str] [-v] [-Q] [-2] [B<-~>] file
=head1 DESCRIPTION
Transforms CSV formatted data (cf. RFC4180) into TSV formated data.
Input is assumed to be UTF-8.
(The input line ends can be both CRLF or LF. The output line ends are LF.)
Warnings/errors would be properly printed on STDERR (as far as the author of
this program experienced).
=head1 EXAMPLE
csv2tsv file.csv > file.tsv
csv2tsv B<-n> '[\n]' file.csv > file.tsv
# "\n" in the CSV cell will be transfomed to [\n].
csv2tsv B<-t> TAB file.csv > file.tsv
# "\t" in the CSV cell will be transfomed to "TAB". UTF-8 characters can be specified.
B<for> i B<in> *.csv ; B<do> csv2tsv -n'"\n"' -t'"\t"' $i > ${i/csv/tsv} ; B<done>
# BASH or ZSH is required to use this "for" statement. Useful for multiple CSV files.
For the safety, when '-t' or '-n' is set with string character specification,
a B<warning> is displayed every time a values in the input cells matches the specified string charatcter
unless B<-Q> is set.
csv2tsv < file.csv > file.tsv
# file name information cannot be passed to "csv2tsv". So the warning messages may lack a few information.
=head1 OPTION
=over 4
=item B<-e> str
Escape character(s) to be used to attach previous to the string matched to the string specified by -t or -n.
=item B<-t> str
What the input TAB character will be replaced with is specified.
=item B<-n> str
What "\n" character in the input CSV cell will be replaced with is specified.
=item B<-s> char
Set CSV field separator anything different from ",".
=item -v
Always tell the existence of "\t" or "\n" even if "-t str" or "-n str" is specified.
=item -Q
No warning even if "\t" or "\n" is included in the cell of input.
=item -2
Double space output, to find "\n" anormality by human eyes.
(For a kind expediency when this program author was firstly making this program)
=item B<-~>
The opposite conversion of csv2tsv, i.e. B<TSV to CSV> conversion.
TABs and LINEENDs will be recovered if the intput was generated by this program "csv2tsv" with the
same specification of "-t", "-n" and "-e".
=item B<-a>
Always enclose all the fields by the double quotations when transforming TSV to CSV.
=item --help
Shows this help.
=item --help ja
Shows Japanese help.
=item --version
Shows the version information of this program.
=back
=head1 AUTHOR
Toshiyuki Shimono
bin4tsv@gmail.com
=head1 HISTORY
2015-09-28 : Firstly created on a whim.
2016-07-06 : Some options are added such as -2.
2016-08-03 : Response to tab and enter characgers.
( run in 0.597 second using v1.01-cache-2.11-cpan-e1769b4cff6 )