我有这样的文本文件:
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.
如何用递增的数字替换所有匹配?
这是一种方法:
原文链接:https://www.f2er.com/bash/384213.html$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.