I am not sure why you will process like this, why not spool the sql result to a file and then process the file. This seems easy to release.
Here we can treat the spool file as the array, it should be ok for you. Just try it.
sqlplus -s ops\$global/developer@sf2a <<!
spool a.txt
select exl_name from exchange_list where rownum<=5; (your sql here)
spool off
!
while read line
do
what you want to do with the each result.
done < a.txt
well it would be bit difficult to satisfy a requirement which requires something like this
#!/bin/sh
//iam reading the data for amounts from database
AMT[]=`sqlplus -s usrname/pswd <<EOD
set pagesize 0 feedback off verify off heading off echo on
select amount from tablename where condition;
EOD`
//writing to a file created at a specifed direcotry using a awk program
echo "$AMT[]" $noofrec | awk '
BEGIN
{
new=$1;
------------------------------------------------------------------
//i need to write the contents of the array in the file (which is created
at a specified location) in a loop that prints in each line contents of amount AMT[] array(as long as elements are there).
------------------------------------------------------------------
hence my problem is to print the elements in the array one by one in lines which are equivalent to no of elements in the array.
for i furthur read this file for processing
Iam able to get the contents into the array from db but couldnt print it in the file
Wait. Are you thinking this code reads the output from sqlplus and sends each line into an array called AMT? It doesn't. You need something like this (at least in BASH):
AMT=(`sqlplus -s usrname/pswd <<EOD >$TMPDIR/$0.$$
set pagesize 0 feedback off verify off heading off echo on
select amount from tablename where condition;
EOD`)
# now you have contents in an array named A.
# print it as a list
echo ${A[@]} | tr ' ' '\n'
# do stuff with each line
for value in ${A[@]}
echo $value
done
Use xargs if you have lines of input and want to do something so that all the lines appear on one output line.
I cannot help you. You are either lying or playing a game. In your first post in this thread, you used code that was to run "#!/bin/sh", which either means the real bourne shell or, in some systems, bash, and definitely not ksh. You simultaneously want to have output from a command put in a shell array and fed into awk. Finally, you make no apparent effort to help yourself.