Insertion of Header record

A header record is to be inserted in the begining of a flat file without using extra file or new file. It should be inserted into same file. Advace thanks for all help...

echo "`awk 'NR==1 {sub(/^/, "Header Record\n") }; {print}' file`" > file

awk '{if(NR > 1) print;else printf "This is a Header\n%s",$0}' file

thanks for the help.... but that is not writing into file instead printing on screen.

That's really a separate issue. Write the output to a temporary file, then move it on top of the original.

commands file >temp
mv temp file

This puts a header into the top of a file without using a temp file...

awk '{a[NR]=$0}END{close(FILENAME);a[0]=h;for(i=0;i<=NR;i++)print a>FILENAME}' h="Header" file

Didn't you try my script?????:confused:

Thanks Ygor Ur script helped me....