使用 sed 将单词替换为空白
Replace word for blank using sed
我有一个包含所有用户的 mysql 赠款的文件。看起来像这样:
GRANT USAGE ON *.* TO 'web_user'@'10.16.%' IDENTIFIED BY PASSWORD '*288A8C32D8C898U779EDA321A6CD6525DB2D3166';
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `users`.* TO 'web_user'@'10.16.%';
GRANT SELECT, INSERT, UPDATE, DELETE ON `zip`.* TO 'web_user'@'10.16.%';
GRANT USAGE ON *.* TO 'alarms'@'10.16.%' IDENTIFIED BY PASSWORD '*E8DEF50F129E0DAF1113382944F603677BA11260';
GRANT SELECT, EXECUTE ON `users`.* TO 'alarms'@'10.16.%';
...
...
...
我需要使用 sed 删除密码。我应该看起来像这样:
GRANT USAGE ON *.* TO 'web_user'@'10.16.%' IDENTIFIED BY PASSWORD
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `users`.* TO 'web_user'@'10.16.%';
GRANT SELECT, INSERT, UPDATE, DELETE ON `zip`.* TO 'web_user'@'10.16.%';
GRANT USAGE ON *.* TO 'alarms'@'10.16.%' IDENTIFIED BY PASSWORD
GRANT SELECT, EXECUTE ON `users`.* TO 'alarms'@'10.16.%';
...
...
...
sed 's/identified by password.*/identified by password/i'
这应该适合你:
sed 's/\(PASSWORD\).*$//' file
如果您想对此 file
进行更改,只需为您的 sed
添加 -i
我有一个包含所有用户的 mysql 赠款的文件。看起来像这样:
GRANT USAGE ON *.* TO 'web_user'@'10.16.%' IDENTIFIED BY PASSWORD '*288A8C32D8C898U779EDA321A6CD6525DB2D3166';
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `users`.* TO 'web_user'@'10.16.%';
GRANT SELECT, INSERT, UPDATE, DELETE ON `zip`.* TO 'web_user'@'10.16.%';
GRANT USAGE ON *.* TO 'alarms'@'10.16.%' IDENTIFIED BY PASSWORD '*E8DEF50F129E0DAF1113382944F603677BA11260';
GRANT SELECT, EXECUTE ON `users`.* TO 'alarms'@'10.16.%';
...
...
...
我需要使用 sed 删除密码。我应该看起来像这样:
GRANT USAGE ON *.* TO 'web_user'@'10.16.%' IDENTIFIED BY PASSWORD
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `users`.* TO 'web_user'@'10.16.%';
GRANT SELECT, INSERT, UPDATE, DELETE ON `zip`.* TO 'web_user'@'10.16.%';
GRANT USAGE ON *.* TO 'alarms'@'10.16.%' IDENTIFIED BY PASSWORD
GRANT SELECT, EXECUTE ON `users`.* TO 'alarms'@'10.16.%';
...
...
...
sed 's/identified by password.*/identified by password/i'
这应该适合你:
sed 's/\(PASSWORD\).*$//' file
如果您想对此 file
进行更改,只需为您的 sed
-i