need help extracting values from string separated by a delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help extracting values from string separated by a delimiter
# 1  
Old 02-21-2011
need help extracting values from string separated by a delimiter

hi guys,

basically what i'm trying to do is fetching a set of columns from an oracle database like so...

Code:
my_row=`sqlplus -s user/pwd << EOF
set head off
select user_id, username from all_users where rownum = 1;
EOF`
echo $my_row

the code above returns...

Code:
1 ADSHOCKER

so then i will create shell variables USER_ID and USERNAME which should hold the value of the my_row. problem is i have no idea how to do it.

are there any functions in shell that would convert my_sql into array that can be accessible like my_row(0) or my_row[0] ?

i am using SunOS by the way.

i'd appreciate any help.

thanks

Last edited by adshocker; 02-21-2011 at 02:57 AM..
# 2  
Old 02-21-2011
Is this the one you need..?
Code:
USER_ID=$(echo $my_row | awk '{print $1}' )
USERNAME =$(echo $my_row | awk '{print $2}' )

This User Gave Thanks to michaelrozar17 For This Post:
# 3  
Old 02-21-2011
Try...
Code:
set -- $my_row
USER_ID=$1
USERNAME=$2

This User Gave Thanks to Ygor For This Post:
# 4  
Old 02-21-2011
thank you very much. both method works very well for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicates separated by delimiter

First post, been browsing for 3 days and came out with nothing so far. M3 C2 V5 D5 HH:FF A1-A2,A5-A6,A1-A2,A1-4 B4-B6,B2-B4,B4-B6,B1-B2output should be M3 C2 V5 D5 HH:FF A1-A2,A5-A6,A1-A4 B2-B4,B4-B6,B1-B2On col 6 and 7 there are strings in form of Ax-Ax and Bx-Bx respectively. Each string are... (9 Replies)
Discussion started by: enrikS
9 Replies

2. Shell Programming and Scripting

How to get the values of multipledot(.) separated fields?

Hello, I have a file which has the following contents : thewall............0000000000200000 kmemfreelater......0000000000000000 kmemgcintvl........0000000000000002 kmeminuse..........00000000223411C0 allocated..........0000000029394000 bucket.......... @.F1000A02800C2158 The mentioned... (4 Replies)
Discussion started by: rahul2662
4 Replies

3. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

4. Shell Programming and Scripting

Needs help in parsing comma separated values

hello experts, i am retrieving values in variables jobKey and jobName within my shell script. these values are returned to me within braces and i am using following command to remove those braces: jobKeys=`echo $jobKeys | sed 's:^.\(.*\).$:\1:'` jobNames=`echo $jobNames | sed... (1 Reply)
Discussion started by: avikaljain
1 Replies

5. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

6. Shell Programming and Scripting

How to loop through space separated values?

How do I loop thru space separated values in a variable? I hate to use very complicated counter increment logic for this kind of simple problem. Expected result(using ksh) $>echo "aaa bbbb cccc" | <looping code here> var=aaa var=bbbb var=cccc $>echo "aaa bbbb cccc" | while IFS=" "... (12 Replies)
Discussion started by: kchinnam
12 Replies

7. UNIX for Dummies Questions & Answers

Get all values separated with spaces(solved)

Hi, i have this text: X (m) 4917536.9627 4917536.9673 0.0090 -0.0046 Y (m) -815726.1383 -815726.1294 0.0061 -0.0089 Z (m) 3965857.4730 3965857.4840 0.0071 -0.0110 X (m) 4917536.9627 4917537.1411 -0.1784 0.1710 Y (m) -815726.1383 -815726.4859 0.3476 0.3489 Z (m) 3965857.4730... (2 Replies)
Discussion started by: limadario
2 Replies

8. Shell Programming and Scripting

extracting delimiter from a file.

hi, pls someone tell me how to extract delimiters from any file and pass it to a unix script.since, im a beginner in unix i find it little bit difficult.how to use awk to do this? (9 Replies)
Discussion started by: sureshmit
9 Replies

9. Shell Programming and Scripting

Extract semicolon separated delimiter

The log reads as follows. fname1;lname1;eid1;addr;pincode1; fname2;lname2;eid2;addr2;pincode2; fname3;lname3;eid3;addr3;pincode3; fname4;lname4;eid;addr4;pincode4; how do i extract only fname and save it in an array similarly for lname and so on i tried reading a file and cutting each... (5 Replies)
Discussion started by: vkca
5 Replies

10. Shell Programming and Scripting

Extracting the values separated by comma

Hi, I have a variable which has a list of string separated by comma. for ex , Variable=/usr/bin,/usr/smrshbin,/tmp How can i get the values between the commas separately using shell scripts.Please help me. Thanks, Padmini. (6 Replies)
Discussion started by: padmisri
6 Replies
Login or Register to Ask a Question