SED: how to add a line at the top of files

Imagine, you have a set of ReST files, and you want to add the statement “author: your name” at the top of each of them. First, identify the files you want to edit and pipe them to sed:

ls *.rst | xargs  sed  -e '1i author: your name'

Where ‘1i’ means insert on the first line. Note also that you must replace sed -e by sed -i -e to replace the file content, otherwise it is like a dry run.

Please follow and like us:
This entry was posted in Linux and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *