我尝试从.my.cnf grep(写入访问)密码,但我还没有得到它。grep来自.my.cnf的密码
的.my.cnf
看起来是这样的:
# longer
# comment text
[clientreadonly]
password=pass1 # comment
port=3306
user=test_ro
socket=/var/lib/mysql/mysql.sock
[client]
password=pass2 # comment
port=3306
user=test
socket=/var/lib/mysql/mysql.sock
,我想给grep pass2
。当然代码不应该太冗长。我结束了
grep 'password=' ~/.my.cnf | sed -e 's/password=//
但thath实际离开pass2
背后的#comment
,我不想更换整个评论(因为它在原有的和愚蠢的,只是取代它长)。所以我需要一个正则表达式来获得pass2
。
主要目标是,到grep密码,所以我可以很容易地在shell命令行中使用它
前行,现在你需要什么样的基础上解释'密码= PASS1#comment'应该被忽略 – Sundeep
最好将上线的基础上以前的通过(只读),但它也可以只采取第二次发生 – Asara
并且在'='之后和'#comment'之前你需要的文本之间总是有空格吗? – Sundeep