I have the scenario where lines to be added on begining and end of the huge files.
I have tried as shown below.
for the first line:
sed -i '1i\'"$FirstLine" $Filename
for the last line:
sed -i '$ a\'"$Lastline" $Filename
But the issue with this command is that it is appending the first line of the file and traversing entire file. For the last line it's again traversing the entire file and appending a last line. Since its very huge file (14GB) this is taking very long time.
How can I add a line to the beginning and another to the end of a file while only reading the file once?