SED Command – How to Insert Text After the Last Line

sed

This sed command inserts a tag to the beginning of a file:

sed -i "1s/^/<?php /" file

How can I insert something to the end of each file with sed?

Best Answer

The simplest way is:

sed -i -e '$aTEXTTOEND' filename

How it works

$ matches the last line (it's a normal sed address; 4aTEXTTOEND would insert after the fourth line), a is the append command, and TEXTTOEND is what to append, filename is the file where the TEXTTOEND will be inserted

Related Question