rename
[migration-tools.git] / csv_ripper
diff --git a/csv_ripper b/csv_ripper
new file mode 100755 (executable)
index 0000000..99e047c
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+# TODO
+# 
+# * add getopt support
+# * use tag generator to expand list of wanted fields?
+# * insertion of constant-value fields
+# * field mapping ("some text" -> 4)?
+
+# csv-extractor FILENAME FIELD_LIST
+
+use strict;
+use warnings;
+
+use Text::CSV;
+
+my $csv = Text::CSV->new({escape_char => "+", allow_loose_quotes => 1});
+
+open CSV, '<', shift or die "Can't open file $!\n";
+
+while (<CSV>) {
+    $csv->parse($_);
+    my @chunks = $csv->fields;
+    my @out = ();
+    for (@ARGV)
+      { push @out, $chunks[$_]}
+    print join("\t", @out), "\n";
+}