Prepending text to a file with sed

Appending content to a file on Linux is pretty easy with >> but there’s no equivalent redirection to prepend content. Luckily, for every file manipulation problem on Linux there’s at least a dozen solutions.

Using sed with -i for inplace replacement of content in a file, you can match ^ for start of line, and then follow with the content you want to replace (in this case, insert).

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.