99e047cd145323a626b5af9225c65a9dbe4bb744
[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({escape_char => "+", allow_loose_quotes => 1});
18
19 open CSV, '<', shift or die "Can't open file $!\n";
20
21 while (<CSV>) {
22     $csv->parse($_);
23     my @chunks = $csv->fields;
24     my @out = ();
25     for (@ARGV)
26       { push @out, $chunks[$_]}
27     print join("\t", @out), "\n";
28 }