通过正则表达式查找和替换的比赛中击为小写 [英] Find by regex and replace match to lowercase in Bash
本文介绍了通过正则表达式查找和替换的比赛中击为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更换匹配给定的正则表达式的小写字母,一个文件的所有内容。这样的:
I would like to replace all contents of a file that match a given regex to their lowercase equivalent. Like:
grep -o '[^ ]*[A-Z][^ ]*.png' file-21-05-2013.sql* | awk '{print tolower($0)}'
上面的一行找到对应的文件至少有一个大写字符的所有字符串并打印小写字母。
The line above finds all strings in the given file that have at least one uppercase character and prints the lowercase equivalent.
我想换成上述
这是否有道理?
推荐答案
如果您使用的是GNU系统,然后GNU SED具有以下扩展名:
If you are using a GNU system then GNU sed has the following extension:
\L
Turn the replacement to lowercase until a \U or \E is found,
下面的命令应该做你所需要的:
The following command should do what you need:
sed "s/\([^ ]*[A-Z][^ ]*.png\)/\L\1/g" file-21-05-2013.sql*
这篇关于通过正则表达式查找和替换的比赛中击为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文