使用awk覆盖输入文件 [英] Overwrite input file using awk

查看:207
本文介绍了使用awk覆盖输入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码行:

awk -F, '{printf "%09d,%d\n" ,$1,$2}' $newDir/$processNew

它执行我想要的操作,但是不是覆盖当前文件,而是在屏幕外打印.

and it does what I want it to, but instead of overwriting the current file, it prints out of screen.

要覆盖当前的$ processNew输入文件,我需要更改什么?

What do I need to change to overwrite the current input file which is $processNew ?

谢谢.

推荐答案

使用GNU awk,您可以

With GNU awk, you can do

gawk -i inplace -options 'script' file ...

gawk -i inplace -v INPLACE_SUFFIX=.bak -options 'script' file ...

ref: https://www.gnu. org/software/gawk/manual/html_node/Extension-Sample-Inplace.html

这篇关于使用awk覆盖输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆