LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 10-20-2011, 10:14 AM   #1
Donoughue
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
splitting of comma separated values file (horizontal) into a list (vertical ) list


Hello All,

I am a real newbie at all of this; both *nix and forums so please forgive me if I make any "faux pax's".

Just so you know, this is not some homework, I am way too old I promise! I am starting out in *nix scripting and wanted to know the best was to make a list of values out of a comma separated file, and place the list of values into a new file. So for example:

file1 contains:
dog, cat, mouse, horse, etc

and I would like the following.

file2 will contain:
dog
cat
mouse
horse

any hints, tips greatly appreciated. Thank You!

(btw I checked previous posts but did not find anything relevant.)
 
Old 10-20-2011, 10:18 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,653

Rep: Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536
Without just giving you the answer:
"tr" can do this. Replace commas with newlines, and optionally remove spaces.
 
Old 10-20-2011, 11:12 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
Agreed, tr is probably the simplest but tools like sed and awk are also available. Have a look at the man page for each and you should make short work of your problem
 
Old 10-20-2011, 02:18 PM   #4
Donoughue
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks Guys! I just needed a nudge in the general direction - hope to meet again in the ether sometime
 
  


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
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 06:50 PM
sorting a list into comma separated list nixlearn Linux - Newbie 22 12-03-2008 07:21 AM
help with comma separated values and what should be a simple script. zaber Programming 10 03-06-2008 01:58 PM
bash syntax: looping through a comma-separated list David the H. Linux - General 10 09-06-2007 11:23 AM
Reading comma-separated data from file MeLassen Programming 4 04-04-2004 03:41 PM


All times are GMT -5. The time now is 10:17 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration