我有很多 .py
文件,其中包含这样一行:
self._cols = [self.foo.bar.relevant_string.str()]
我需要将 relevant_string
大写,才能得到这个
self._cols = [self.foo.bar.RELEVANT_STRING.str()]
总共约有 100 个。
有没有办法用 bash/awk/perl 做到这一点?我试过这样的事情
perl -pe 's/self.foo.bar./uc($&)/e' *.py
但是它把捕获的区域大写了,而不是后面的部分。
最佳答案
使用 GNU sed:
$ echo 'self._cols = [self.foo.bar.relevant_string.str()]' |
sed -E 's/(self\.foo\.bar\.)([^.]+)/\1\U\2/'
self._cols = [self.foo.bar.RELEVANT_STRING.str()]
关于bash - 将终端中同一位置的不同短语大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55399445/