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 08-14-2007, 02:31 AM   #1
naren_0101bits
Member
 
Registered: Jul 2004
Location: Guntur
Posts: 44

Rep: Reputation: 15
Need help in writing simple shell script to format names


Hi All, I just started learning shell scripts.

There is one text file names.txt having names seperated by comma like

Krishna,Pavana,Aravind,Alpha

How can i write a script using for loop to get those names output in seperate lines as

Krishna
Pavana
Aravind
Alpha


Use cut command also

Thanks in advance.
 
Old 08-14-2007, 03:53 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
This wouldn't be homework would it? I'd just do 'sed 's/,/\n/g' names.txt' with GNU sed.
 
Old 08-14-2007, 04:16 AM   #3
naren_0101bits
Member
 
Registered: Jul 2004
Location: Guntur
Posts: 44

Original Poster
Rep: Reputation: 15
Definitely not a homework Digiot. Hahaha
Thanks a lot for the help
 
Old 08-14-2007, 10:59 AM   #4
dave201
LQ Newbie
 
Registered: Oct 2005
Location: Camelot
Distribution: cent, RH core, slax, slackware... *buntu...
Posts: 28

Rep: Reputation: 15
use the built in IFS variable. I use ksh korn shell, so this is for korn.


Code:
#!/bin/ksh

IFS=","  #the IFS you can set to whatever you want your file to be delimited (separated) by.  IFS works in conjuction with the "read" routine in this case.

while read name1 name2 name3 name4 name5
do

echo $name1
echo $name2
echo $name3

done < names.txt

exit 0

Last edited by dave201; 08-14-2007 at 11:27 AM.
 
  


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
Shell Script to Get Folder Names firefoxlinux Programming 6 09-27-2007 02:56 PM
Help writing a simple script Garibaldi3489 Linux - General 10 12-18-2004 06:22 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 03:40 AM
Simple script writing help - digital camera EuroJovi Linux - General 2 02-01-2004 04:01 PM
Putting Script Names In Shell Scripts sayble96 Linux - Newbie 4 12-17-2003 10:16 PM

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

All times are GMT -5. The time now is 09:49 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