in reply to Re^2: Extracting data from each line that matches a email address from a Log file (Tab delimited)
in thread Extracting data from each line that matches a email address from a Log file (Tab delimited)
#!/usr/bin/perl -w use strict; use Text::CSV_XS; use IO::File; my $filename = 'hdi.csv'; my $column_to_search = 1; my $wanted_value = 'Sweden'; my $csv = Text::CSV_XS->new({binary=>1}); my $fh = IO::File->new($filename) or die $!; while (my $cols = $csv->getline($fh)) { last unless @$cols; next unless defined $cols->[$column_to_search] and $cols->[$column_to_search] eq $wanted_value; for (0,1,3) { $cols->[$_] = '' unless defined $cols->[$_]; } print join(' ',$cols->[0],$cols->[1],$cols->[3]),"\n"; }
|
|---|