how to seperate space in a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to seperate space in a string
# 1  
Old 05-08-2008
Data 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  
Old 05-08-2008
ksh:

for i in `cat filename`
do
echo $i
done
# 3  
Old 05-08-2008
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  
Old 05-08-2008
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  
Old 05-08-2008
Thank you boss its workingggggg fineeeeeeeeee
thank youuuuuuuuuu
# 6  
Old 05-08-2008
You can also use the cut utility for this purpose...
Code:
firstfield=`echo $string1 | tr -s " " | cut -d " " -f 1`
echo $firstfiled

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove all matches containing a string until its next space

I want to delete all matches in a text following this pattern: Each match starts with linux- Each match ends with a space (Remove linux-* until immediate next space) EXAMPLE: From this text: ibudev1 libudev1 libweather-ion7 libxatracker2 linux-generic linux-headers-generic... (4 Replies)
Discussion started by: Tribe
4 Replies

2. Shell Programming and Scripting

Comparing string's with space

How can i comparing string's whith blank spaces? I have this problem: DIF1="STRING 1212" DIF2="STRING 1212" if then echo "Differents" else echo "Equals" fi Error: 1212}: unknown test operator (3 Replies)
Discussion started by: Xedrox
3 Replies

3. Shell Programming and Scripting

String comparison with a space

Hello Gurus, I've searched enough to find what I wanted and finally ended up creating a thread. I'm in the process of coding something like below sed -n -e "s/.*\(successfully completed\).*/\1/p" xxx.log read status if ] then #sleep 3; echo "Export... (4 Replies)
Discussion started by: rajivan
4 Replies

4. Shell Programming and Scripting

add only one space after each word in a string

hi, I have this string: a="abc def ghi jkl mno pqr" how can I display this to: abc def ghi jkl mno pqr # only one space each (14 Replies)
Discussion started by: h0ujun
14 Replies

5. Shell Programming and Scripting

Remove last space in a string?

I have a customer file now and would like to separate the names into two cells in a spreadsheet. Here is my data as an example: SHAWN R KEEGAN shawn r scroggin Shawn Regan Shawn Reilly The first two have the middle initial so I'd like to include them in the "first name" field and the last... (11 Replies)
Discussion started by: Grassy
11 Replies

6. Shell Programming and Scripting

Replacing a string with a space

I'm trying to replace a string "99999999'" with the blank where ever is there in the file. Could you please help in unix scripting. Thank You. (6 Replies)
Discussion started by: vsairam
6 Replies

7. Shell Programming and Scripting

Storing string with space (urgent)

hi i have a file content like my_file: 1US8738297897918000 000 000 i used while IFS= read line do echo "$line" | grep '^\ then last=`echo "$line" | cut -c 3-20` echo "$last" fi done < $my_file but it is writing blank spaces into the o/p fie (1 Reply)
Discussion started by: Satyak
1 Replies

8. UNIX for Dummies Questions & Answers

awk to seperate a string that has a dash

Hello I have this string XYZ-ABC DFT-ERT QWE-TYU I want to get the part after the dash. how to do that? thanks (2 Replies)
Discussion started by: melanie_pfefer
2 Replies

9. UNIX for Dummies Questions & Answers

how to check if a string consist of any space?

hi all how do i check if a string consist of any space by using shell script. i have the following code while test -z $string do //prompting for another string if string is length 0 done when i type "a b" it give me an error test: a: binary operator expected thanks (7 Replies)
Discussion started by: yang
7 Replies

10. Shell Programming and Scripting

Storing string with space

Hi all I am trying this simple command: a="abc abc" echo $a output is: abc abc But expected output shoould be :abc abc i.e spaces in real string are geting truncated to one space everytime. Plz Help. (4 Replies)
Discussion started by: rahul303
4 Replies
Login or Register to Ask a Question