line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::csv2tsv; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
47766
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
54
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
App::csv2tsv - A command transforming from CSV to TSV handling tab/line-ends with escaping, durable for reverse operation. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.54 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.54'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
csv2tsv [B<-t> str] [B<-n> str] [-v] [-Q] [-2] [B<-~>] file |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Transforms CSV formatted data (cf. RFC4180) into TSV formated data. |
26
|
|
|
|
|
|
|
Input is assumed to be UTF-8. |
27
|
|
|
|
|
|
|
(The input line ends can be both CRLF or LF. The output line ends are LF.) |
28
|
|
|
|
|
|
|
Warnings/errors would be properly printed on STDERR (as far as the author of |
29
|
|
|
|
|
|
|
this program experienced). |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 EXAMPLE |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
csv2tsv file.csv > file.tsv |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
csv2tsv B<-n> '[\n]' file.csv > file.tsv |
36
|
|
|
|
|
|
|
# "\n" in the CSV cell will be transfomed to [\n]. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
csv2tsv B<-t> TAB file.csv > file.tsv |
39
|
|
|
|
|
|
|
# "\t" in the CSV cell will be transfomed to "TAB". UTF-8 characters can be specified. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
B i B *.csv ; B csv2tsv -n'"\n"' -t'"\t"' $i > ${i/csv/tsv} ; B |
42
|
|
|
|
|
|
|
# BASH or ZSH is required to use this "for" statement. Useful for multiple CSV files. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
For the safety, when '-t' or '-n' is set with string character specification, |
45
|
|
|
|
|
|
|
a B is displayed every time a values in the input cells matches the specified string charatcter |
46
|
|
|
|
|
|
|
unless B<-Q> is set. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
csv2tsv < file.csv > file.tsv |
49
|
|
|
|
|
|
|
# file name information cannot be passed to "csv2tsv". So the warning messages may lack a few information. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 OPTION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=over 4 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item B<-t> str |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
What the input TAB character will be replaced with is specified. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item B<-n> str |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
What "\n" character in the input CSV cell will be replaced with is specified. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item -v |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Always tell the existence of "\t" or "\n" even if "-t str" or "-n str" is specified. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item -Q |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
No warning even if "\t" or "\n" is included in the cell of input. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item -2 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Double space output, to find "\n" anormality by human eyes. |
74
|
|
|
|
|
|
|
(For a kind expediency when this program author was firstly making this program) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item B<-~> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The opposite conversion of csv2tsv, i.e. B conversion. |
79
|
|
|
|
|
|
|
(Every cell will be encloded by double quotes.) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item --help |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Shows this help. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item --help ja |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Shows Japanese help. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item --version |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Shows the version information of this program. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
"Toshiyuki Shimono", C<< >> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 BUGS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
103
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
104
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SUPPORT |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
perldoc App::csv2tsv |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
You can also look for information at: |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * CPAN Ratings |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * Search CPAN |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=back |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Copyright 2018 "Toshiyuki Shimono". |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
147
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
148
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
149
|
|
|
|
|
|
|
(at your option) any later version. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
152
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
153
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
154
|
|
|
|
|
|
|
GNU General Public License for more details. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
157
|
|
|
|
|
|
|
along with this program. If not, see L. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; # End of App::csv2tsv |