Parsing MySQL Output in Bash

How can I redirect the output of a mysql query with table delimiter as delimiter? I am trying to use this code:

mysql -u root -h localhost -D cronjob -e "select * from cron_list" > query.txt

      

What I am expecting is output like this:

| id |  datetime  | recurrency |          command          |
|  1 | 2014-10-10 |    daily   | bash /media/data/daily.sh |
|  2 | 2014-10-09 |  minutely  |           conky           |

      

But when I use this code it gives me output like

 id   datetime   recurrency           command          
  1  2014-10-10     daily    bash /media/data/daily.sh 
  2  2014-10-09   minutely             conky           

      

So how can I redirect the output from the terminal to a delimited file like in the terminal? Sorry for bad english

+3


source to share


1 answer


From man mysql

:

- table, -t

Display output in table format. This is the default for interactive but can be used to generate table output in batch mode.

Note -t

- this is the default behavior, but not every time you connect to a file. This is why, in this case, you must make it explicit.




Other interesting options for other types of outputs:

- silent, -s

Quiet mode. Produce less output. This option can be set multiple times to produce less and less output.

This parameter results in imprecise output format and escaping special characters. Escaping can be disabled using raw mode; see the description of the -raw option.

- missing column names , -N

Don't write column names in the results.

- html, -H

Produce HTML output.

+6


source







All Articles