在地方用awk编辑 [英] in place editing using awk

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

问题描述

我要在文件上添加一行说 F1 用awk。结果
难道还有比下一个更好的办法?

I want to add a line at top of file say f1 using awk.
Is there a better way than the following?

awk 'BEGIN{print "word"};{print $0}' f1 > aux;cp aux f1;\rm aux<br/>

awk中是否有类似的sed?

Does awk has something like -i option in sed?

推荐答案

为什么不使用SED - 这将让解决方案更加简单。

Why not use sed - it would make the solution more straightforward

$sed -i.bak '1i\
word
' <filename>

这篇关于在地方用awk编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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