strip csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting strip csv file
# 1  
Old 05-10-2011
strip csv file

Hi everyone,
I hope someone can help me:
i am trying to get some info from a csv file, after i awk the column i need , i made a selection and output it in a file.
now i need to get a list from this file, but i stuck with some fields.

basically i have a text file with next data:

3 ,"Simone Johnson"
6 ,"Niels Blaat"
7 ,"Peter Pan"
16 ,"Frans de Boer- Randall Jack- Hanneke Truus- Jaap Doos"
17 ,"Jaap Bart"
21 ,"Kees Piet"

and the output must be:

Simone Johnson 3
Niels Blaat 6
Peter Pan 7
Frans de Boer 16
Randall Jack 16
Hanneke Truus 16
Jaap Doos 16
Jaap Bart 17
Kees Piet 21


thanks a lot for youre help.
# 2  
Old 05-10-2011
Try this

Code:
awk -F',|"' '{split($3,x,"- ");for(i=1;i<=length(x);i++){print x[i]" "$1}}' infile

regards,
Ahamed

Last edited by ahamed101; 05-10-2011 at 06:40 PM..
# 3  
Old 05-10-2011
Try:
Code:
perl -F"," -lane '$F[1]=~s/\"//g;@x=split /- /,$F[1];for $i (@x){print "$i $F[0]"}' file

# 4  
Old 05-11-2011
Thank you guys, it works great Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strip file based on pattern

Hi, I am stripping the below file based on a pattern: **Starts**02-MAY-2017 03:48:13 **Ends**02-MAY-2017 03:48:13 +---------------------------------------------------------------------------+ Start of log messages ... (2 Replies)
Discussion started by: Prasannag87
2 Replies

2. 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

3. Shell Programming and Scripting

Strip time from CSV File?

Hi, I've been trying (and failing miserably) all morning to strip from a CSV file the time from it. Can somebody point me in the right direction on how to do this using sed or awk? The file looks like: "James","07/20/2009-14:40:11" "Steve","08/06/2006-02:34:37"... (5 Replies)
Discussion started by: nmuntz
5 Replies

4. Shell Programming and Scripting

how to strip rows from a text file?

Can an expert kindly write an efficient Linux ksh script that will strip rows with no numbers from a text file? Supposing there are three rows that text file called text.txt : "field1","field2","field3",11,22,33,44 "field1","field2","field3",1,2,3,4 "field1","field2","field3",,,, The... (5 Replies)
Discussion started by: ihot
5 Replies

5. Shell Programming and Scripting

How to strip non numerical data out of file?

Hi, How can I remove all non numerical data from line, so I don't want to delete the line but to have only the numbers. e.g.: ######### 123 aaa124 125bbb 126 127 ######### So I want all the leading and trailing non numerical stuff(letters/white space/tabs anything else except... (10 Replies)
Discussion started by: Juha
10 Replies

6. UNIX for Dummies Questions & Answers

How to strip the contants from a file

Hi, I have some EDI data which 830, 862 and 997. Here is the sample data: ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051215~184 3~U~00200~000011432~0~P~< GS~FA~TC11A~U1CAD~051215~1843~000011432~X~002002 ST~997~0001 AK1~SH~1168 AK2~856~11680001 AK5~A... (2 Replies)
Discussion started by: isingh786
2 Replies

7. Shell Programming and Scripting

How to strip apostrophe from a file

I am trying to remove or replace various extraneous characters from a file so that subsequent processes work correctly. The characters that is giving me trouble is the apostrophe '. The command I 'm trying is sed 's/\'//g' ${IN_WRK_DIR}/file1 > ${IN_WRK_DIR}/file2 in a Korn script on HP... (8 Replies)
Discussion started by: aquimby
8 Replies

8. UNIX for Dummies Questions & Answers

trying to strip the first 4 char. of a file out via commandline

im kind alost. i beleave its a sed command. but i cant seem to find it in my book. can someone point me in the write direction. i know this is extreamly sloppy. but this is what i did untill i can figure out how to manipulate the filename namespace. an ls on the directory where this would run... (2 Replies)
Discussion started by: Optimus_P
2 Replies
Login or Register to Ask a Question