gpt4 book ai didi

bash - 将终端中同一位置的不同短语大写

转载 作者:行者123 更新时间:2023-11-29 09:36:01 25 4
gpt4 key购买 nike

我有很多 .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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com