Hi,
I'm facing some problem with printing the values in the variables
I have passed all the database values into the variable, but when i echo the variable i get the values printed in one line
var=`echo <query> | database`
echo $var
or
awk 'BEGIN {printf("%s\n","'"${var}"'")}'
this prints
table1 <value> table2 <value> table3 <value> table4 <value>
But the above needs to be printed as
table1 <value>
table2 <value>
table3 <value> and so on
Can anyone please help me
methyl
2
It would help to see the output from
echo <query> | database
Your problem is that Shell Environment Variables are not files and the line break character is lost.
But. assuming that the database writes the output in pairs (with a line terminator), we need to read them as pairs:
echo <query> | database | while read table value
do
echo "${table} ${value}"
done
prash_b
3
Thanks Methyl
The output i get from the command is
echo <query> | database
table1 <value>
table2 <value>
table3 <value>
but if i pass the values to the variable then i'm getting
table1 <value> table2 <value> table3 <value> table4 <value>
Try echo "$var". Without that, shell expansion is going to squeeze all the whitespace together.
methyl
5
Try my solution from post #2 . Should work.