Help needed to format mysql output

Hi all,

Does anyone know how to format the output from mysql from within a shell script?

i.e.

RESULT=`mysql command`

echo ${RESULT}

the ${RESULT} only displays the output on one line instead of how mysql would display it as columns etc

This would be a lot easier in PHP using the built in DB functionality v. exec from a shell command.

Hi.

I suggest that you try this:

echo "${RESULT}"

to get the same result as mysql directly, because the newlines are suppressed when you omit the quotes ... cheers, drl

My experience is that you should know the nature of the MySQL query, i.e. number and size of rows and columns before deciding on how to format the output.

Generally, we should read most queries into an array first, or an array of arrays and then print the output in loop where we can format the output properly.

Simply adding a newline to a row with large fields, blobs, and or many columns, will be messy.

There should be some structure to the query unless the query is trivial like getting only a few small fields.