SED: insert text at the top of a bunch of files

at a line at the top of a file

Imagine, you have a set of files ending in .txt, and you want to add the statement #header at the top of each of them. Then, simply type:

ls *.txt | xargs  sed  -e '1i #header'

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.