【发布时间】:2018-02-21 08:26:27
【问题描述】:
我想抓取一个文件的子字符串来获取centos中mysql的默认密码。 这是我用来获取密码的命令:
sudo grep 'temporary password' /var/log/mysqld.log
结果是:
2018-02-21T07:03:11.681201Z 1 [Note] A temporary password is generated for root@localhost: >KkHAt=#z6OV
现在,我使用此命令仅获取密码并删除不必要的内容,因此我可以在脚本中使用它:
sudo grep 'temporary password' /var/log/mysqld.log | cut -d ':' -f 4 | cut -d ' ' -f 2
但使用 2 次切割似乎很丑陋。有没有我可以使用的其他命令或工具,或者更优雅的方式来做到这一点?
【问题讨论】: