Hi infinite_scale,
This is the command I can think of for appending text to first and last line of a file. Ofcourse you can use script to make it better but this is the simplest way I could think to achieve what you have mentioned
Code:
cat testing > newfile && echo "This is first line" > testing && cat newfile >> testing && echo "This is the last line" >> testing
This is how it works. I have got a file name testing which contains say 100 lines. What this command will do it will first copy all those lines in a newfile. Then it will insert a text using echo command say "This is the first line". Then it will append the text which is there in newfile back to testing file. At the end using echo you will put the text "This is the last line"