MER*_*ose 6 sed text-processing regular-expression
我想替换我只收到的大写字母的名字。这些名称与其他应保持原样的信息混合在一起。AUTH:
在该行的开头将其标识为应该替换名称的行。
TITLE: Average title
AUTH: SUPERMAN
AFF: Something
AUTH: THE NEW ONE
AFF: Berlin
AUTH: MARS-MENSCH
AFF: Planet Mars
Run Code Online (Sandbox Code Playgroud)
那么应该是
TITLE: Average title
AUTH: Superman
AFF: Something
AUTH: The New One
AFF: Berlin
AUTH: Mars-Mensch
AFF: Planet Mars
Run Code Online (Sandbox Code Playgroud)
我的问题与 Unix 问题“除了第一个(大写)字母以外的西里尔文大写字母之外的所有小写字母”有关但不同,因为我使用罗马字母并且未能采用建议的解决方案。
为了获得相应的行,我使用egrep -rl ^"AUTH:"
然后我跟随| xargs sed -r -i '/(AUTH:)/ ??? /\1/g'
我不知道用什么替换???
的地方。
> sed '/^AUTH/{s/^AUTH: //;s/\b\([[:alpha:]]\)\([[:alpha:]]*\)\b/\u\1\L\2/g;s/^/AUTH: /;}' file
TITLE: Average title
AUTH: Superman
AFF: Something
AUTH: The New One
AFF: Berlin
AUTH: Mars-Mensch
AFF: Planet Mars
Run Code Online (Sandbox Code Playgroud)