in reply to Re: 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)

Here is how I modified the script to do what I need.
use strict; use warnings 'all'; use Text::CSV_XS; open STDIN,"c:\\scripts\\20051030.log" or die $!; my $columns; open STDOUT, ">Answers.out" or die "can't redirect stdout"; my $parser = Text::CSV_XS->new ({sep_char => "\t"}); while (<STDIN>) { next if ! length $_; if (! $parser->parse ($_)) { warn "Error parsing: $_"; next; } my @columns = $parser->fields(); next if ! defined $columns[20]; print "$columns[0], $columns[1], $columns[7], $columns[18], $columns [19]\n"; }
I get this in return... Use of uninitialized value in concatenation (.) or string at C:\scripts\Xsv.pl l ine 26, <STDIN> line 392. I still not know where I put in what I am searching for. and I need to search two fields "Recipient-Address, Sender-Address" If my search word "Auser" (case should not matter)is in either field the give me the 5 columns
  • Comment on Re^2: Extracting data from each line that matches a email address from a Log file (Tab delimited)
  • Download Code

Replies are listed 'Best First'.
Re^3: Extracting data from each line that matches a email address from a Log file (Tab delimited)
by GrandFather (Saint) on Nov 01, 2005 at 18:13 UTC

    Are you setting the correct seperator character in Text::CSV_XS->new ({sep_char => "\t"});?


    Perl is Huffman encoded by design.
Re^3: Extracting data from each line that matches a email address from a Log file (Tab delimited)
by GrandFather (Saint) on Nov 01, 2005 at 18:43 UTC

    Add use Data::Dumper; and update your next if ! defined $columns[20]; line to (print Dumper (\@columns)), next if ! defined $columns[20]; to see what is actually in @columns.


    Perl is Huffman encoded by design.
Re^3: Extracting data from each line that matches a email address from a Log file (Tab delimited)
by talexb (Chancellor) on Nov 01, 2005 at 16:20 UTC

    What does the debugger tell you is undefined?

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re^3: Extracting data from each line that matches a email address from a Log file (Tab delimited)
by jZed (Prior) on Nov 01, 2005 at 17:15 UTC
    I think you want something like this:
    #!/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"; }