LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-10-2003, 12:08 AM   #1
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 437

Rep: Reputation: 30
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
 
Old 11-10-2003, 01:32 AM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 215

Rep: Reputation: 31
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
 
Old 11-10-2003, 01:49 AM   #3
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 437

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Culling Data from a CSV file to output in excel jterr02 Programming 2 05-19-2006 05:58 AM
C++ read csv file row into vector taban1 Programming 3 11-08-2004 03:01 PM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 09:23 PM
csv to fixed-length file roballen Programming 0 03-11-2004 04:12 AM
tar and CSV lhoff Linux - Newbie 1 10-29-2002 01:23 PM


All times are GMT -5. The time now is 04:31 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration