LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Split CSV, field as filename (http://www.linuxquestions.org/questions/programming-9/split-csv-field-as-filename-495104/)

richmur 10-24-2006 09:28 AM

Split CSV, field as filename
 
I have a csv file with 2 columns, first contains a code e.g. X467 the second contains some text. Any ideas how to create a bunch of txt files with the first field as the filename and the second field as the contents of the txt file - thanks

sample csv:

X467, This is the sample text
Z5439, This is some more sample text
Y56, Final line

jim mcnamara 10-24-2006 09:34 AM

Code:

awk -F, '{ print $2 > $1 }' myfile.csv
Assuming I understood what you wanted....

richmur 10-24-2006 09:39 AM

Perfect - much appreciated! That worked a charm, I had been trying to do it using perl, grep and anything else I could think of.


All times are GMT -5. The time now is 01:09 PM.