加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在Bash中解析MySQL输出

发布时间:2020-12-15 21:51:48 所属栏目:安全 来源:网络整理
导读:如何将表边框的 mysql查询输出重定向为分隔符? 我尝试使用此代码: mysql -u root -h localhost -D cronjob -e "select * from cron_list" query.txt 我期望输出如下: | id | datetime | recurrency | command || 1 | 2014-10-10 | daily | bash /media/da
如何将表边框的 mysql查询输出重定向为分隔符?
我尝试使用此代码:

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

我期望输出如下:

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

但是,当我使用该代码时,它会给我输出

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

那么,如何将终端的输出重定向到带终端的分隔符的文件?
抱歉英文不好

解决方法

来自man mysql:

–table,-t

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

注意-t是默认行为,但不管何时管道到文件.这就是为什么在这种情况下你必须明确.

其他有趣的选项,用于其他类型的输出:

–silent,-s

Silent mode. Produce less output. This option can be given multiple
times to produce less and less output.

This option results in nontabular output format and escaping of
special characters. Escaping may be disabled by using raw mode; see
the description for the –raw option.

–skip-column-names,-N

Do not write column names in results.

–html,-H

Produce HTML output.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读