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

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

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

Is this the one you need..?

USER_ID=$(echo $my_row | awk '{print $1}' )
USERNAME =$(echo $my_row | awk '{print $2}' )
1 Like

Try...

set -- $my_row
USER_ID=$1
USERNAME=$2
1 Like

thank you very much. both method works very well for me.