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 and shell scripting languages here.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-08-2008
kittusri9 kittusri9 is offline
Registered User
  
 

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.
  #2 (permalink)  
Old 05-08-2008
ludwig ludwig is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 8
ksh:

for i in `cat filename`
do
echo $i
done
  #3 (permalink)  
Old 05-08-2008
kittusri9 kittusri9 is offline
Registered User
  
 

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
  #4 (permalink)  
Old 05-08-2008
yongitz yongitz is offline
Registered User
  
 

Join Date: Apr 2008
Location: Philippines
Posts: 68
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

  #5 (permalink)  
Old 05-08-2008
kittusri9 kittusri9 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 40
Thank you boss its workingggggg fineeeeeeeeee
thank youuuuuuuuuu
  #6 (permalink)  
Old 05-08-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
You can also use the cut utility for this purpose...

Code:
firstfield=`echo $string1 | tr -s " " | cut -d " " -f 1`
echo $firstfiled

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0