使用awk将修改保存到位 [英] Save modifications in place with awk
本文介绍了使用awk将修改保存到位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习awk
,我想知道是否存在将更改写入文件的选项,与sed
类似,在这里我将使用-i
选项将更改保存到文件中.
I am learning awk
and I would like to know if there is an option to write changes to file, similar to sed
where I would use -i
option to save modifications to a file.
我确实知道我可以使用重定向来编写更改.但是awk
中有一个选项可以做到吗?
I do understand that I could use redirection to write changes. However is there an option in awk
to do that?
推荐答案
最新的GNU Awk(因为 就地"文件编辑:
In latest GNU Awk (since 4.1.0 released), it has the option of "inplace" file editing:
[...]使用新工具构建的"inplace"扩展名可以用来模拟GNU"
sed -i
"功能. [...]
[...] The "inplace" extension, built using the new facility, can be used to simulate the GNU "
sed -i
" feature. [...]
示例用法:
$ gawk -i inplace '{ gsub(/foo/, "bar") }; { print }' file1 file2 file3
要保留备份:
$ gawk -i inplace -v INPLACE_SUFFIX=.bak '{ gsub(/foo/, "bar") }
> { print }' file1 file2 file3
这篇关于使用awk将修改保存到位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文