79c24585a41c4be34da1f61f833b1e87a31bd11e
[migration-tools.git] / csv_extractor
1 #!/usr/bin/perl
2
3 # TODO
4
5 # * add getopt support
6 # * use tag generator to expand list of wanted fields?
7
8 # csv-extractor FILENAME FIELD_LIST
9
10 use strict;
11 use warnings;
12
13 use Text::CSV;
14
15 my $csv = Text::CSV->new({escape_char => "+", allow_loose_quotes => 1});
16
17 open CSV, '<', shift or die "Can't open file $!\n";
18
19 while (<CSV>) {
20     $csv->parse($_);
21     my @chunks = $csv->fields;
22     my @out = ();
23     for (@ARGV)
24       { push @out, $chunks[$_]}
25     print join("\t", @out), "\n";
26 }