Add a header to a file with Shell script (sed)

Nov 11, 2016

Today I was re-generating the documentation for a REST API written in PHP, with
Laravel. To generate the documentation, one would have to call a Laravel command first.
That command would create a Markdown page. And since in this project I am using Jekyll
for the project site, the final step was adding a header to the file, so that Jekyll
can recognize that content as a blog post.

Laravel allows you to add custom commands to your project, so I decided to write a command
that would call the other command that generates the documentation, and add an extra step
of adding the header to the Markdown file.

Here’s the shell script part, that allows you to add a header to a file, in place (i.e.
it will alter and save the change your file).