How to parse csv format?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to parse csv format?
# 8  
Old 07-08-2010
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?

Installation of Perl modules BTW:
Code:
perl -MCPAN -e 'install Text::CSV'

# 9  
Old 07-08-2010
Hi Pludi,

Thanks for the information.
# 10  
Old 07-08-2010
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!
# 11  
Old 07-08-2010
Hi.

The module Text::CSV is available in a Debian repository.

Many people like to to use the package manager to install items. With apt-get using the environment:
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0

here's a simulated install:
Code:
$  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)

Best wishes ... cheers, drl
# 12  
Old 07-08-2010
I also faced the same problem of "illegal reference to array a" when I run the command
Code:
"awk '{if ($0~/"/) {split($0,a,"\",\"")} else {split($0,a,",")}} {for (i=1;i<=length(a);i++) {sub(/"/,"",a[i]);print a[i]}}' urfile

Then later I modified the above command a bit and it is working fine. The command & output is as below:
Code:
bash-3.00$ cat urfile
/tmp/foo/,MODIFY,bar/toto
"/tmp/foo, bar/","ATTRIB,ISDIR","toto, tata/foobar"

bash-3.00$ awk '{a[0]=""; if($0~/^"/) {FS="\",\""; split($0,a,"\",\"");} else {FS=",";split($0,a,",");}} { for(x=1;x<=NF;x++) {sub(/"/,"",$x); print $x;}}'  urfile
/tmp/foo/
MODIFY
bar/toto
/tmp/foo, bar/
ATTRIB,ISDIR
toto, tata/foobar

Hope this helps. Thanks.

Last edited by Franklin52; 07-08-2010 at 09:02 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a script to parse data and output to csv

I am not too savvy with arrays and am assuming that what I am looking for needs arrays. This is my requirement. So I have the raw data that gets updated to a log as shown below StudentInfo: FullInfo = { Address = Newark Age = 20 Name= John } StudentInfo:... (2 Replies)
Discussion started by: sidnow
2 Replies

2. Shell Programming and Scripting

How to parse this file using awk and output in CSV format?

My source file looks like this: Cust-Number = "101" Cust-Name="Joe" Cust-Town="London" Cust-hobby="tennis" Cust-purchase="200" Cust-Number = "102" Cust-Name="Mary" Cust-Town="Newyork" Cust-hobby="reading" Cust-purchase="125" Now I want to parse this file (leaving out hobby) and... (10 Replies)
Discussion started by: Balav
10 Replies

3. Shell Programming and Scripting

Parse csv files by their names

HI all I have multiple csv files with the names VAR1_VAR2_VAR3_VAR4.csv All the files have the same structure inside just values change. I am trying to retrieve data from those files by fixing at each time one or more VAR. I tried to write a script but I have 2 problems: 2-... (1 Reply)
Discussion started by: Jhon.c
1 Replies

4. Shell Programming and Scripting

how to parse this file and obtain a .csv or .xls

Hello Expert, I have a file in the following format: SYNTAX_VERSION 5 MONITOR "NAME_TEMPLATES" DESCRIPTION "Monitors for contents of error " INTERVAL "1m" MONPROG "script.sh NAME_TEMPLATES" MAXTHRESHOLD GEN_BELOW_RESET SEVERITY Major ... (17 Replies)
Discussion started by: Ant-one
17 Replies

5. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

6. Shell Programming and Scripting

Parse csv file

Hi, Our requirement is to parse the input file(.csv format). The each column in the file is delimited with comma. We need to take each column and apply some business validation rule. If data itself contains comma, then those fields are enclosed with double quotes ("). We can see this double... (7 Replies)
Discussion started by: vfrg
7 Replies

7. Shell Programming and Scripting

Parse XML file into CSV with shell?

Hi, It's been a few years since college when I did stuff like this all the time. Can someone help me figure out how to best tackle this problem? I need to parse a file full of entries that look like this: <eq action="A" sectyType="0" symbol="PGR" exch="CA" curr="VEF" sess="NORM"... (7 Replies)
Discussion started by: Pcushing
7 Replies

8. Shell Programming and Scripting

Unix Script to parse a CSV

I am writing a unix script that will parse a CSV and edit the values. My CSV looks like this 0,0,0,0,1,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0 10,11,7,0,4,12,2,3,7,0,11,3,12,4,0,5,5,4,5,0,8,6,12,0,9,3,3,0,2,7,8... (16 Replies)
Discussion started by: RJ17
16 Replies

9. Shell Programming and Scripting

CSV File parse help in Perl

Folks, I have a bit of an issue trying to obtain some data from a csv file using PERL. I can sort the file and remove any duplicates leaving only 4 or 5 rows containing data. My problem is that the data contained in the original file contains a lot more columns and when I try ro run this script... (13 Replies)
Discussion started by: lodey
13 Replies

10. UNIX for Advanced & Expert Users

How to Parse a CSV file into a Different Format

Hi I have a CSV file with me in this format Currency, USD, EUR, USD, 1.00, 1.32, EUR, 0.66, 1.00, How do I transpose the file to get to the format below. currency, currency, rate USD, USD, 1.00 USD, EUR, 1.32 EUR, USD, 0.66 EUR, EUR, 1.00 Thanks for your help We are using... (2 Replies)
Discussion started by: cdesiks
2 Replies
Login or Register to Ask a Question