我有一个文件:
one one one
one one
one one
one
one
one
此命令替换 5 倍于 1, “ 3” 的 5 个命令
$ awk {for(i=1; NF>=i; i++)if($i~/one/)a++}{if(a<=5) gsub("one", "three"); print } file
three three three
three three
one one
one
one
one
同样的事情,但六倍:
$ awk {for(i=1; NF>=i; i++)if($i~/one/)a++}{if(a<=6) gsub("one", "three"); print } file
three three three
three three
one one
one
one
one
如何改进上述例子?
three three three
three three
three one
one
one
one
谢谢你的帮助