The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove unregconized space from a string Ricole UNIX for Dummies Questions & Answers 3 02-29-2008 12:35 AM
Storing string with space rahul303 Shell Programming and Scripting 4 10-04-2007 07:26 AM
Need help to seperate data getdpg Shell Programming and Scripting 4 08-30-2006 02:28 AM
How to trim the white space around a string in C program hxm1303 High Level Programming 2 09-06-2005 12:24 AM
row seperate inquirer Shell Programming and Scripting 13 08-12-2003 02:26 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2008
Read Only
 

Join Date: Apr 2008
Posts: 40
Unhappy how to seperate space in a string

Dear Members,

I have string like this
string1="file2.txt file4.txt kittu.txt file1.txt"

in this i need to cut spaces and take each one has one file
output should be
---------
fileslist:4

file2.txt
file4.txt
kittu.txt
file1.txt

is it possible, please tell me how it possible

thanks
Krish.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-08-2008
Registered User
 

Join Date: Feb 2008
Posts: 8
ksh:

for i in `cat filename`
do
echo $i
done
Reply With Quote
  #3 (permalink)  
Old 05-08-2008
Read Only
 

Join Date: Apr 2008
Posts: 40
Hi,

its not file
its string


string1="file2.txt file4.txt kittu.txt file1.txt"
echo $string1
for i in `cat string1`
do
echo $i
done

but its not working
Reply With Quote
  #4 (permalink)  
Old 05-08-2008
Registered User
 

Join Date: Apr 2008
Location: Philippines
Posts: 20
You had an error because you don't have a file called string1.

try this:

Code:
string1="file2.txt file4.txt kittu.txt file1.txt"
for i in `echo $string1`
do
echo $i
done
or just

Code:
string1="file2.txt file4.txt kittu.txt file1.txt"
for i in $string1
do
echo $i
done
Reply With Quote
  #5 (permalink)  
Old 05-08-2008
Read Only
 

Join Date: Apr 2008
Posts: 40
Thank you boss its workingggggg fineeeeeeeeee
thank youuuuuuuuuu
Reply With Quote
  #6 (permalink)  
Old 05-08-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 285
You can also use the cut utility for this purpose...
Code:
firstfield=`echo $string1 | tr -s " " | cut -d " " -f 1`
echo $firstfiled
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0