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
# 8  
Old 11-24-2010
Thanks a lot for all your help.

I currently use cygwin and it seems that I cannot redirect anything to an external file (???) the script is blocked and doesn't ask for a date.

Anyway again thank you very much

---------- Post updated 11-24-10 at 02:46 AM ---------- Previous update was 11-23-10 at 11:28 AM ----------

Hello again,

Well I imported the script on a HP-UX environment and it's not0 executing the way it should :


Code:
#!/bin/sh
awk 'BEGIN{printf("Entrez la date : "); getline date < "-"}
$0 ~ date {f=1}
f
/^[0-9]{2}\//{f=0}
f' toto.csv

Results in :

Code:
$ ./extract.sh
Entrez la date : 02/12/2010
02/12/2010;;;;;;;;;;

=> and that's all

It doesn't give me the actions for a date :

Code:
02/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";

Help please

Last edited by Scott; 11-24-2010 at 04:49 AM.. Reason: Code tags, please...
# 9  
Old 11-24-2010
Try this:
Code:
awk 'BEGIN{printf("Enter the date : "); getline date < "-"}
$0 ~ date {f=1;print;next}
/^[0-9]{2}\//{f=0}
f
' toto.csv

# 10  
Old 11-24-2010
Again thank you.

Now I have to find a way (by myself) to get everything a little bit cleaner because the output is not very sexy.

Can you tell me what is the signification of all this :
Code:
/^[0-9]{2}\//{f=0}


Last edited by Scott; 11-24-2010 at 04:53 AM..
# 11  
Old 11-24-2010
Quote:
Originally Posted by freyr
Again thank you.

Now I have to find a way (by myself) to get everything a little bit cleaner because the output is not very sexy.

Can you tell me what is the signification of all this :

/^[0-9]{2}\//{f=0}
Code:
/^[0-9]{2}\//{f=0}

If the first 2 characters of the line are numeric and the third character is a slash (the next date) assign 0 to the variable f.
This User Gave Thanks to Franklin52 For This Post:
# 12  
Old 11-24-2010
Thanks a lot for all your help Smilie Smilie Smilie Smilie Smilie Smilie Smilie
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