LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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-09-2003, 11:08 PM   #1
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

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, 12:32 AM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

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, 12:49 AM   #3
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

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



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 04:58 AM
C++ read csv file row into vector taban1 Programming 3 11-08-2004 02:01 PM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 08:23 PM
csv to fixed-length file roballen Programming 0 03-11-2004 03:12 AM
tar and CSV lhoff Linux - Newbie 1 10-29-2002 12:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:42 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration