sed: how to add text at the end of the file

Use the $a syntax and sed:

sed -i '$a some text' filename

-i parameter means in place. To test without changing the original file, remove the -i option. The results will be print on the screen.

A previous post explained how to insert a line anywhere but for completeness. Indeed, with the $a syntax you append content and therefore you can append text after a line. Therefore you cannot append text before the first line. Instead use the i command:

sed -i  '1i some text on first line' filename
Please follow and like us:
This entry was posted in Linux and tagged . Bookmark the permalink.

2 Responses to sed: how to add text at the end of the file

Leave a Reply

Your email address will not be published.