0

我在 MacOS 10.12 中工作,我有 100 个文件,例如:

My file <structure_is> like this <and_maybe_like> this,
but not quite like this.
But there might be <stuff> like this, too.

我一直在尝试将 <> 中的所有项目转换为大写,以查看文件如下所示:

My file <STRUCTURE_IS> like this <AND_MAYBE_LIKE> this,
but not quite like this.
But there might be <STUFF> like this, too.

我尝试使用:

find . -name "\*" | xargs sed 's/\<([a-z_][^>]*)\>/\U&/g'

我也尝试过使用 gsed (自制):

find . -name "\*" | xargs gsed 's/\<([a-z_][^>]*)\>/\U&/g'

但我得到的只是文件本身的内容到标准输出。

我该怎么做呢?

最亲切的问候!

4

2 回答 2

1

这适用于 Linux:sed 's/<[^>]*>/\U&/g' file

我不知道是否\U只有 GNU sed。

或者,perl:

perl -pe 's/<.*?>/\U$&/g' file
于 2017-08-25T15:25:40.863 回答
0

<在正则表达式中是文字<,而\<在 GNU sed 中至少是单词分隔符转义序列。因此,只需更改您的\<to<\>to >,您的gsed脚本就可以正常工作。

除非您知道自己在做什么,否则永远不要逃避角色。如果你想要一个文字字符c并且不知道你是否需要转义它,那么你使用它[c]比使用更安全,\c因为至少前者不能将它变成一个正则表达式元字符。

于 2017-08-25T17:03:23.780 回答