Editing using awk

I want to add a line on top of say f1 file 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 have something like the -i option in sed?

+4
source share
2 answers

Why not use sed - it would make the solution simpler

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

An alternative way to do this:

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

All Articles