#!/usr/bin/perl
use Text::CSV;
my $file = 'inpit.csv';
my $csv = Text::CSV->new();
open (CSV, "<", $file) or die $!;
while (<CSV>) {
chomp;
if ($csv->parse($_)) {
my @columns = $csv->fields();
$i=0;
print "\n\nLINE $. \n";
while (<@columns>) {
print "$columns[$i] \n";
$i = $i + 1 ;
}
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV;
Thanks pravin27,
I forgot to say that I'm trying to find a shell language solution.
Altough your approach is interesting, I can't make it work. Do I need to do something special?
Can't locate Text/CSV.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at parser.pl line 4.
BEGIN failed--compilation aborted at parser.pl line 4.
Thanks rdcwayx,
I like your awk approach because it can fit my needs. But I get the following error:
awk: line 2: illegal reference to array a
What did I do wrong?
---------- Post updated at 22:29 ---------- Previous update was at 19:33 ----------
Hi there,
I did it another way (inspired by rdcwayx's idea) with sed:
The whole idea is to be able to interpret the csv output of inotifywait.
Hi,
you have install the attached module.
1) Save this tar file in /tmp/Text-CSV-1.18.tar
2) Untar the file.
3) INSTALLATION
Go to the directory "/tmp/Text-CSV-1.18"
To install this module type the following:
Looks almost like "How can I use X to do Y?". Here's Z: why not use the --format switch of inotifywait to define your own format, eg with a semicolon as delimiter?
Thx pludi.
This is really embarasing now. I don't know if I started my project with another version of inotify but I completely missed that option.
Thank you very much!
$ apt-get -s install libtext-csv-perl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libtext-csv-xs-perl
The following NEW packages will be installed:
libtext-csv-perl libtext-csv-xs-perl
( ... )
Inst libtext-csv-perl (1.06-1 Debian:5.0.5/stable)
Inst libtext-csv-xs-perl (0.52-1 Debian:5.0.5/stable)
Conf libtext-csv-perl (1.06-1 Debian:5.0.5/stable)
Conf libtext-csv-xs-perl (0.52-1 Debian:5.0.5/stable)