免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1228 | 回复: 2

[文本处理] grep为什么没有返回完整的行 [复制链接]

论坛徽章:
1
黑曼巴
日期:2018-08-23 09:13:38
发表于 2018-08-23 09:13 |显示全部楼层
mysql执行show databases的输出如下:
1.png

[root@cloudvm01 ~]# mysql -uroot -ppassword -e "show databases" -h10.3.237.86
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| binlog             |
| mysql              |
| performance_schema |
| sjtjci             |
| sjtjmetadata       |
| sys                |
+--------------------+

再执行搜索时:
[root@cloudvm01 ~]# mysql -uroot -ppassword -e "show databases" -h10.3.237.86|grep  "Database"
mysql: [Warning] Using a password on the command line interface can be insecure.
Database

输出的只有Database,但是这一行应该是  | Database           |

搜索mysql也是一样
[root@cloudvm01 ~]# mysql -uroot -ppassword -e "show databases" -h10.3.237.86|grep  "mysql"
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql

搜索"-"和"|"搜不到:
[root@cloudvm01 ~]# mysql -uroot -ppassword -e "show databases" -h10.3.237.86 2>&1|grep  "-"
[root@cloudvm01 ~]#

[root@cloudvm01 ~]# mysql -uroot -ppassword -e "show databases" -h10.3.237.86 2>&1|grep  "|"
[root@cloudvm01 ~]#

论坛徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16赛季CBA联赛之北京
日期:2016-07-06 15:42:0715-16赛季CBA联赛之同曦
日期:2016-06-12 10:38:0915-16赛季CBA联赛之佛山
日期:2016-05-27 11:54:56黄金圣斗士
日期:2015-12-02 11:44:35白银圣斗士
日期:2015-11-25 14:32:43白银圣斗士
日期:2015-11-23 12:53:352015亚冠之布里斯班狮吼
日期:2015-10-21 16:55:482015亚冠之首尔
日期:2015-09-01 16:46:052015亚冠之德黑兰石油
日期:2015-08-31 11:39:192015亚冠之萨济拖拉机
日期:2015-08-28 21:06:5315-16赛季CBA联赛之广东
日期:2016-07-12 14:58:53
发表于 2018-08-23 14:21 |显示全部楼层
这不是grep的问题, 是MySQL的行为

在非交互模式情况下, 是没有表格输出的, 如果在非交互模式要想有表格输出, 加上 -t | --table 参数

mysql -t -uroot -p ... | grep ...

论坛徽章:
1
黑曼巴
日期:2018-08-23 09:13:38
发表于 2018-08-27 12:52 |显示全部楼层
回复 2# reyleon

非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP