tags:

views:

405

answers:

2

I want to add a line at top of file say f1 using awk
Is there a better way than :
awk 'BEGIN{print "word"};{print $0}' f1 > aux;cp aux f1;\rm aux
does awk has something like -i option in sed.

+1  A: 

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

$sed -i.bak '1i\
word
' <filename>
Beano
How can I echo newlines using the above script
Neeraj
Just add them in - replace "word" with "work<cr>word"
Beano
A: 

An alternate way to do this is
sed -i '1s:^: Word1\nWord2 :' file

Neeraj