我正在尝试提出一个正则表达式,可以将任何单词大写,但保留任何大写的缩写和首字母缩略词。
例如,我希望'伦敦'成为'伦敦',但'洛杉矶'保持不变。理想情况下,任何两个字符单词都是大写的,例如'la'→'LA'。
使用大写位很容易,但缩写/首字母缩略词是我的意思。任何提示都将非常感激。
答案 0 :(得分:2)
尝试使用GNU sed:
sed 's/\b.\B/\u&/g;s/\b..\b/\U&/g' file
$ cat file Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. $ sed 's/\b.\B/\u&/g;s/\b..\b/\U&/g' file Lorem Ipsum IS Simply Dummy Text OF The Printing And Typesetting Industry. Lorem Ipsum Has Been The Industry'S Standard Dummy Text Ever Since The 1500s, When AN Unknown Printer Took A Galley OF Type And Scrambled IT TO Make A Type Specimen Book.