Separate String Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separate String Shell Script
# 1  
Old 04-13-2009
Separate String Shell Script

Hi guys,
I am a beginner in shell script..
How can I separate a string coming from a parameter in spaces ?

Ex:
input: test.sh abcd
output: a b c d

Thanks
Dusse
# 2  
Old 04-13-2009
Hi,
echo "abcd" | sed -e 's/abcd/a b c d/'

Bye
# 3  
Old 04-13-2009
Code:
echo 'abcd' | sed 's/./ & /g'

# 4  
Old 04-13-2009
Quote:
Originally Posted by sauron
Hi,
echo "abcd" | sed -e 's/abcd/a b c d/'

Bye

oh this is helpful.

why not just:

Code:
echo a b c d

???

Code:
echo $* | sed -e 's/./& /g'

# 5  
Old 04-13-2009
Cool vgersh99,

i love being useful end learning at the same time.

Bye
___________

Computers are like air-conditioners
they stop working properly
when you open windows
# 6  
Old 04-13-2009
Thanks for the reply..
now I can print in the screen the string with spaces

but how can I attribute this in a variable?

I tried these and doesn't work

var = `$1 | sed 's/./ &/g'`
var = `$1 | sed 's/./ &/g'`
var = `expr $1 | sed 's/./ &/g'`
# 7  
Old 04-13-2009
Code:
var1=`echo $1 | sed 's/./ &/g'`
var2=`echo $1 | sed 's/./ &/g'`
var3=`echo $1 | sed 's/./ &/g'`


Last edited by quirkasaurus; 04-13-2009 at 12:11 PM.. Reason: forgot echo...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Separate string based on delimiter

Hi, for fd in $(grep "/tmp/" hello.properties)The grep gives me the below output: deploydir=/tmp/app1/dfol prodir= /tmp/hello/prop ...... Now i want to store /tmp/app1/dfol then /tmp/hello/prop in a variable so that i can check if those folders files exists or not. The delimiter would... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Want to separate one string

Hello friends. I have on file with following data Jhon Status: Form successfully submitted Maria Status:Form successfully submitted Shyne Status: Form submission pending. Liken Status:Form successfully submitted David Status:Form successfully submitted Rich Status: Form... (7 Replies)
Discussion started by: Nakul_sh
7 Replies

3. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

4. Shell Programming and Scripting

Get string between quotes separate by commas

I'm a beginner with shell and tried to do this per hours and everytinhg gives different want i do. So I have a lot of file in *.csv ( a.csv, b.csv ...) in each file csv , it has some fields separeted by commas. ----- "joseph";"21","m";"groups";"j.j@gmail.com,j.j2@hotmail.com"... (6 Replies)
Discussion started by: flaviof
6 Replies

5. UNIX for Advanced & Expert Users

shell script to send separate mails to different users from a text file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: Code: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884... (0 Replies)
Discussion started by: giridhar276
0 Replies

6. Shell Programming and Scripting

Calling DB user from separate file in Shell script

Hi All, I need to execute a SQL via shell script and i am connecting to Oracle DB by this way $USERNAME1/$PASSWORD1@$STRING1 and i need to get username, password and string from someother file stored in the Unix Directory. $Username, $Password and $String is stored in File A in Path A and i want... (3 Replies)
Discussion started by: sathish.tn
3 Replies

7. UNIX for Dummies Questions & Answers

need assistance on Calling DB user from separate file in Shell script

Hi All, I need to execute a SQL via shell script and i am connecting to Oracle DB by this way $USERNAME1/$PASSWORD1@$STRING1 and i need to get username, password and string from someother file stored in the Unix Directory. $Username, $Password and $String is stored in File A in Path A and i want... (1 Reply)
Discussion started by: sathish.tn
1 Replies

8. Shell Programming and Scripting

Need help with shell, trying to append or separate values in a string

Ok. I for the life of me cant figure out how to do this. I need Help. So here is what I'm trying to do. I have a block of text. They are FIPS codes for counties. Below is the block. There are probably a few ways to do this. The first line starting with ARC021....... this line is a list of... (2 Replies)
Discussion started by: chagan02
2 Replies

9. UNIX for Dummies Questions & Answers

to separate values from a string

Hi I would like to take input from user like username/password@connectstring I should be able to cut the username and password and connect string for example if someone enters like sam/sammy@ora1 my program should take sam as username sammy as password and ora1 as connectstring and... (3 Replies)
Discussion started by: ssuresh1999
3 Replies

10. Shell Programming and Scripting

Separate string

i am a biginner of shell scripting.please help me how can i seperate a string in two parts.eg.user given sting is"oi2ehello".i want to make 2 string string1=oi2e and string2=hello (3 Replies)
Discussion started by: arghya_owen
3 Replies
Login or Register to Ask a Question