mysql - mysql输出的列宽

标签 mysql bash shell

mysql 命令的输出未正确对齐标题​​(使用脚本)。 这是script.sh中的sql命令

#!/usr/bin/bash
echo "select * from hw_inventory "| mysql --host=localhost --user=root --database=monitor > /tmp/inventory

这在/tmp/inventory 中提供了以下输出

ip_address      entity_index    entity_physname entity_physdesc entity_serial
10.212.0.1      1000    Switch 1        WS-C3850-12S    FOC1842U117
10.212.0.1      1009    Switch 1 - Power Supply A       Switch 1 - Power Supply A       LIT18300URD
10.212.0.1      1010    Switch 1 - Power Supply B       Switch 1 - Power Supply B       LIT183506NH
10.212.0.1      1034    Switch 1 FRU Uplink Module 1    2x1G 2x10G Uplink Module        FOC18363NJX

正如您所看到的,对齐方式(制表符)与开关 1 的文本应在实体_physname 下开始的方式不同。 它需要类似于以下输出:

ip_address      entity_index    entity_physname              entity_physdesc            entity_serial
10.212.0.1      1000            Switch 1                     WS-C3850-12S               FOC1842U117
10.212.0.1      1009            Switch 1 - Power Supply A    Switch 1 - Power Supply A  LIT18300URD
10.212.0.1      1010            Switch 1 - Power Supply B    Switch 1 - Power Supply B  LIT183506NH
10.212.0.1      1034            Switch 1 FRU Uplink Module 1 2x1G 2x10G Uplink Module   FOC18363NJX

有什么想法吗? 提前致谢

最佳答案

要格式化 mysql 的输出,请使用 -t 参数

"select * from hw_inventory "| mysql -t --host=localhost --user=root --database=monitor > /tmp/inventory

关于mysql - mysql输出的列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33875254/

相关文章:

php - 使用PHP使SQL列爆炸成变量

php - 是否可以对 MySQL 进行混合覆盖/追加批量写入?

windows - 为什么运行 npm test 结果是 : '.' is not recognized as an internal or external command, 可运行程序或批处理文件。?

linux - fork 服务一启动就重新启动?

linux - 列出其内容可以与多个字符串中的任何一个匹配的所有文件名的最快方法

c - 在 C 中,如何创建和发送 shell 变量?

android - android安装apk的问题

c# - 使用 MySQL .Net Core ADO 执行多查询

php - 它不会在数据库中插入值

linux - 我怎样才能在bash shell脚本中编写这种for循环?