我有一个这样的文本文件:
AAAAAA this is some content.
This is AAAAAA some more content AAAAAA. AAAAAA
This is yet AAAAAA some more [AAAAAA] content.
我需要用递增的数字替换所有出现的 AAAAAA
,例如,输出如下所示:
1 this is some content.
This is 2 some more content 3. 4
This is yet 5 some more [6] content.
如何用递增的数字替换所有匹配项?
最佳答案
这里有一种方法:
$ awk '{for(x=1;x<=NF;x++)if($x~/AAAAAA/){sub(/AAAAAA/,++i)}}1' file
1 this is some content.
This is 2 some more content 3. 4
This is yet 5 some more [6] content.
关于bash - 如何用 BASH 中的递增数字替换所有匹配项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23577516/