This is something that you get in csv
- if the delimiter is part of the field, it gets quoted. That suddenly makes the task of parsing it MUCH harder, because you can't just split on a delim.
Fortunately, if perl
is an option, you have the Text::CSV
module that handles this case:
#!/usr/bin/env perl
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV -> new ( { 'sep_char' => '|' } );
while ( my $row = $csv -> getline ( *STDIN ) ) {
print $row -> [1],"\n";
}
Could probably condense this to an inline/pipeable if you prefer - something like:
perl -MText::CSV -e 'print map { $_ -> [1] ."\n" } @{ Text::CSV -> new ( { 'sep_char' => '|' } ) -> getline_all ( *ARGV )};