Reputation: 19759
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?
Upvotes: 4
Views: 2771
Reputation: 19759
An alternate way to do this is:
sed -i '1s:^: Word1\nWord2 :' file
Upvotes: 1
Reputation: 7831
Why not use sed - it would make the solution more straightforward
$sed -i.bak '1i\
word
' <filename>
Upvotes: 2