I create a file (output) from another file (input) using awk (skipping the header): awk 'NR==1{next} $3==1 {print $1\t$2}' input > outputI then have header information I can only calculate afterwards, which I add using sed:sed -i 1s/^/head1\thead2\n/ outputHowever, the sed is pretty slow, I'm wondering if there is a better way of  doing it? Like saving the awk result and then writing the file after I have the header information?
How to add a header to the output of an awk command afterwards?
text processing;awk
After more googling, I found this question:Change the header in a huge file without rewriting the whole file. To prevent having to rewrite the entire file when adding in the header, I printed a dummy header of a minimum amount of bytes (by padding with zeros) while creating the file: awk 'NR==1{print dummyhead100\tdummyhead20000; next} $3==1 {print $1\t$2}' input > outputI then make a file (or string variable) with the new head as header.tsv, and replace the dummy header in-place (after making sure the dummy and new headers are the same number of bytes) using dd: dd conv=notrunc obs=1 if=header.tsv of=outputThis way output is edited in-place, and I don't have to wait for the whole file to be copied, or have to keep it in memory. 