How to extract data from csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract data from csv file
# 1  
Old 11-23-2010
How to extract data from csv file

Hello everybody,

Here is my problem, I don't know anything about shell programming and my boss is actually asking me to develop a shell script in order to get values in a csv file from a specific date.

Here is a sample of the csv file :
Code:
Date;Enchaînement;Titre;Libellé ;calendrier;Heure début;Heure fin;Durée estimée;Durée réelle;"Durée ré-évaluée ou 
informations complémentaires";Contraintes, dépendances et criticités;

and below the values :
Code:
01/12/2010;;;;;;;;;;;
;bp_101;"IE001 (4 UT)
BP_10101 à BP_10104"; INTERFACE ENTRANTE : TOTO => GAGA;SPF;;;;;;"bg00<nn><zz>.bp
sur bonne ou mauvaise fin de bp_102 (FORMP)";
;bp_209;"IE017 (3 UT)
BP_20901 à BP_20903";INTERFACE ENTRANTE :TOTO => GAGA;SPF;;;;;;"gesiaaaa.bp 
Exclusif";

02/12/2010;;;;;;;;;;
;bp_101;"IE001 (4 UT)
BP_10101 à BP_10104"; TOTO : GOGO => GAGA;SPF;;;;;;"bg00<nn><zz>.bp
sur bonne ou mauvaise fin de bp_102 (FORMP)"
;bp_209;"IE017 (3 UT)
BP_20901 à BP_20903";TOTO => GAGA;SPF;;;;;;"gesiaaaa.bp 
Exclusif"

As you can see each date corresponds to various actions

Would you know a script that would ask for a date and then parse the csv file in order to grab the different actions refering to this date ?

Thanx a lot for your help...

Last edited by Franklin52; 11-23-2010 at 09:13 AM.. Reason: Please use code tags
# 2  
Old 11-23-2010
Something like this?
Code:
awk 'BEGIN{printf("Enter the date : "); getline date < "-"}
$0 ~ date {f=1}
f
/Exclusif/{f=0}
' file

# 3  
Old 11-23-2010
Thanks a lot for your help. Now I have a script which is asking for a specific date.

But, the problem is that it reads only 2 lines (???) whereas I have many for a specific date :
Code:
01/12/2010;;;;;;;;;;;
;Action_1;; Comment;Comment;;;;;;"File Comment";
;Action_2;; Comment;Comment;;;;;;"Exclusif";
;Action_3;; Comment;Comment;;;;;;"Not exclusif";
;Action_4;; Comment;Comment;;;;;;"Another File Comment";
;Action_5;; Comment;Comment;;;;;;"File Comment";
;Action_6;; Comment;Comment;;;;;;"File Comment";

How to do to make it print every kind of action for a specific date ?

Thanx a lot for your help

Last edited by Scott; 11-24-2010 at 04:48 AM.. Reason: Code tags
# 4  
Old 11-23-2010
Code:
awk 'BEGIN{printf("Enter the date : "); getline date < "-"} $0 ~ date{f=1}!NF{f=0}f' file

This User Gave Thanks to danmero For This Post:
# 5  
Old 11-23-2010
Perhaps somrhing like this?
Code:
awk 'BEGIN{printf("Enter the date : "); getline date < "-"}
$0 ~ date {f=1}
f
/^[0-9]{2}\//{f=0}
' file

# 6  
Old 11-23-2010
@Franklin52 & @danmero : I greatly appreciate your help

Now everything seems to be more or less OK but How can I redirect the output to a file ?

Thanx again
# 7  
Old 11-23-2010
Quote:
Originally Posted by freyr
@Franklin52 & @danmero : I greatly appreciate your help

Now everything seems to be more or less OK but How can I redirect the output to a file ?

Thanx again
Code:
awk '..' infile > outfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

2. Shell Programming and Scripting

Shell script to extract data from csv file

Hi everyone, I have a csv file which has data with different heading and column names as below. Static Data Ingested ,,,,,,,,,,,,Known Explained Rejections Column_1,column_2,Column_3,Column_4,,Column_6,Column_7,,% Column_8,,Column_9 ,Column_10 ,... (14 Replies)
Discussion started by: Vivekit82
14 Replies

3. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 7 columns having values say column 1,column 2.....column 7 as below along with their values. Name, Address,... (7 Replies)
Discussion started by: Vivekit82
7 Replies

4. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

5. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

6. Shell Programming and Scripting

Extract and parse XML data (statistic value) to csv

Hi All, I need to parse some statistic data from the "measInfo" -eg. 25250000 (as highlighted) and return the result into line by line, and erasing all other unnecessary info/tag. Thought of starting with grep "measInfoID="25250000" but this only returns 1 line. How do I get all the output... (8 Replies)
Discussion started by: jackma
8 Replies

7. Shell Programming and Scripting

extract data in a csv file based on a certain field.

I have a csv file that I need to extract some data from depending on another field after reading info from another text file. The text file would say have 592560 in it. The csv file may have some data like so Field 1 Field2 Field3 Field4 Field5 Field6 20009756 1 ... (9 Replies)
Discussion started by: GroveTuckey
9 Replies

8. Shell Programming and Scripting

Extract last cell of csv file

How do I extract the last cell in a column of a csv file using linux shell scripting? Or alternatively, how do I get the number of cells of a csv file? (2 Replies)
Discussion started by: locoroco
2 Replies

9. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

10. Shell Programming and Scripting

extract .csv file

Hi all I am new to unix . I need to write a script that extracts some data from oracle into a .csv file with heading of the columns in the file SO i created the following two scripts but they are not working ac.sql (this is the sql file that i will call inside the shell script when i run... (1 Reply)
Discussion started by: rajesh_tns
1 Replies
Login or Register to Ask a Question