In unix - how to append data in start of file ?
Please advise.
Thanks
In unix - how to append data in start of file ?
Please advise.
Thanks
Use an editor.
No kidding - what do you want to achieve in which way?
Add a new line in top of file using awk
awk 'NR==1 {print "new information"}1' oldfile > newfile
awk 'NR==1 {print "new information"}1' oldfile > newfile
above command is working well.
i want to understand bit:- why you wrote 1 after print command in awk
below "1" i am asking for :
"}1' oldfile > newfile
NR==1
Search argument (look for line number 1)
{print "new information"}
program actions (run this if search argument above is true)
1
Serarch argument (since its 1, it will always be true, and always run next program action)
Since there are no program action after 1, it run the default action, that is print the line.
So 1
prints all line and NR==1
adds text before first line is printed
Or do it inside BEGIN
block:
awk 'BEGIN{ print "Prepend Text" } 1' file