LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   CSV File (http://www.linuxquestions.org/questions/programming-9/csv-file-114292/)

AMMullan 11-10-2003 12:08 AM

CSV File
 
Hey all :)

I have a CSV file that I want to make into a big list, i.e.

fred,harry,frank

into

fred
harry
frank


What would be the best way to do this, I know I could run the command (a getent for samba), filter it through to one file and then replace with vi but I thought there'd be a better way...

Any ideas would be really helpful :)

eric.r.turner 11-10-2003 01:32 AM

You can do it with a single sh command line. The following command creates the list by replacing the commas with newlines, and sorts it in asciibetical order:

Code:

cat input.csv | sed 's/,/\n/g' | sort
If you want to, you can redirect the output to another file:

Code:

cat input.csv | sed 's/,/\n/g' | sort > output.list

AMMullan 11-10-2003 01:49 AM

The power of sed. I've got a couple of scripts with it in but I still haven't figured it out lol :P

Thanks for ur help, worked perfectly :)


All times are GMT -5. The time now is 02:24 AM.