to separate values from a string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to separate values from a string
# 1  
Old 10-06-2008
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 assign to different variables

Thanks in advance
# 2  
Old 10-06-2008
will this do??
Code:
 
read input?"enter value"
echo "$input"|awk -F\/ '{print $1$2}'

# 3  
Old 10-07-2008
Quote:
Originally Posted by ssuresh1999
if someone enters like

sam/sammy@ora1

my program should take sam as username sammy as password and ora1 as connectstring and assign to different variables

There is no need for any external command:
Code:
input=sam/sammy@ora1
up=${input%@*}
username=${up%/*}
password=${up#*/}
connectstring=${input#*@}

# 4  
Old 10-07-2008
Thanks so much for your answers
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. 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

3. 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

4. Shell Programming and Scripting

Divide data with specific column values into separate files

hello! i need a little help from you :) ... i need to split a file into separate files depending on two conditions using scripting. The file has no delimiters. The conditions are col 17 = "P" and col 81 = "*", this will go to one output file; col 17 = "R" and col 81 = " ". Here is an example. ... (3 Replies)
Discussion started by: chanclitas
3 Replies

5. 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

6. 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

7. Shell Programming and Scripting

How to separate the values in perl??

Hi, I have a string like that and i have to separate the key and value pair. $str="OWN - NLM STAT- MEDLINE DA - 19990311 DCOM- 19990311 LR - 20061115 AB - The perlfaq comprises several documents that answer the most commonly asked questions about Perl and Perl programming. It's divided... (3 Replies)
Discussion started by: vanitham
3 Replies

8. Shell Programming and Scripting

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 (15 Replies)
Discussion started by: dusse
15 Replies

9. 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

10. UNIX for Advanced & Expert Users

insert pipe in file to separate values

hi all... i need your help, because i donīt know what to do... i have a flat file like this: B065200512312004123111010000061451 000021853 B065200512312004123111020000621907 000417802 B065200512312004123111030000005214 000005861 B065200512312004123111040000120133 000088448 and i need... (5 Replies)
Discussion started by: DebianJ
5 Replies
Login or Register to Ask a Question