Print awk output in same line ,For loop

My code is something like below.

#/bin/bash
for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'`
do
echo $i
ORACLE_SID=`echo $line | awk '{print $2}'`
USERNAME=`echo $line | awk '{print $1}'`
done

=============
But echo $i output comes like

oradummydb01
ora_pmon_dummydb011
oraxyzdb01
ora_pmon_xyzdb011

is there a way I can get output of awk from for loop in straight line. so I can export ORACLE_SID and Username without redirect to file of executing:

ORACLE_SID=`ps -ef | grep pmon | awk $8`

Thanks for Help in advance.

You could replace:

echo $i
ORACLE_SID=`echo $line | awk '{print $2}'`
USERNAME=`echo $line | awk '{print $1}'`

By either one of the following..

Single line (per 'task'):

echo "$i $line" | awk '{print $1,$2,$3}'

Or with linebreaks:

echo "$i $line" | awk -v NL="\n" '{print $1 NL $2 NL $3}'

hth

Untested, but might come close:

#/bin/bash
ps -ef | awk '/pmon/ && ! ( /bash/ || /grep/ || /perl/ || /asm/ || /MGMT/) {print $1,$8}' |
while read USERNAME ORACLE_SID
do	printf 'USERNAME="%s", ORACLE_SID="%s"\n' "$USERNAME" "$ORACLE_SID"
	# Do whatever else you want to do with these two variables.
done

However, if the script you showed us produces the output you showed us, it means that $1 or $8 in the script expands to an empty field (and I would assume that it would be the 8th field that is empty.

The code above assumes that you know that the 1st and 8th fields contain the data you want and that the code you showed us is not exactly what you ran. If that assumption is not correct, we need to see the output produces by ps -ef and we need to know what output you are hoping to extract as a result of running your script. Since line is never set in the script you showed us, the USERNAME and ORACLE_SID shell variables script are probably being set to empty strings (unless line is set to some non-empty string in the environment inherited by your script).

The behavior of awk can also vary from system to system. Please also tell us what operating system you're using so we can better understand what you're trying to do.

With all those exclusions, is "pmon" the right thing to match? And, as the first field in ps 's IS the (already known and matched for?) username, do you really need to obtain it from your script?