in place editing using awk

邮差的信 提交于 2020-01-14 13:25:28

问题


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/>

Does awk has something like -i option in sed?


回答1:


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

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



回答2:


An alternate way to do this is:

sed -i '1s:^: Word1\nWord2 :' file


来源:https://stackoverflow.com/questions/910121/in-place-editing-using-awk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!