use*_*747 -2 bash perl awk sed
我正在寻找一个perl/awk/sed命令来自动增加第7列中的数字.文件knownfile.txt中的示例行:
该文件具有格式和7列.
today is a great day and it
is also an amazing day tomorrow now
blahblah foo today build number is 5928
Run Code Online (Sandbox Code Playgroud)
我要保留所有格式,只需更换5928与5929和保存文件
我试过了:
awk '/blahblah/{ $7++; print $0 }' filename > tmp && mv tmp filename
Run Code Online (Sandbox Code Playgroud)
它增加了数字,我认为它保留了格式,但它只将编辑的行打印到文件中.
$ cat file
today is a great day and it
is also an amazing day tomorrow now
blahblah foo today build number is 5928
$ awk '{sub(/[[:digit:]]+$/,$NF+1)}1' file
today is a great day and it
is also an amazing day tomorrow now
blahblah foo today build number is 5929
Run Code Online (Sandbox Code Playgroud)
如果那不符合您的要求,那么请认真考虑您发布的样本输入和预期输出,因为我们必须继续这样做.