问题
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