this is actually bearable with \set verbosity terse
[migration-tools.git] / csv_ripper
1 #!/usr/bin/perl
2
3 # TODO
4 #
5 # * add getopt support
6 # * use tag generator to expand list of wanted fields?
7 # * insertion of constant-value fields
8 # * field mapping ("some text" -> 4)?
9
10 # csv-extractor FILENAME FIELD_LIST
11
12 use strict;
13 use warnings;
14
15 use Text::CSV;
16
17 my $csv = Text::CSV->new( {binary => 1});
18
19 open CSV, '<', shift or die "Can't open file $!\n";
20
21 while (<CSV>) {
22     $csv->parse($_);
23     die "Bad data on line $.\n$_\n" if ($csv->error_diag);
24     my @chunks = $csv->fields;
25     my @out = ();
26     for my $chunk (@ARGV)
27       { push @out, $chunks[$chunk] }
28     print join("\t", @out), "\n";
29 }