Björn Brynjúlfur

Text stream editing with sed

I wanted to edit 123 text files by inserting a new line into each one. After some Googling I managed to create a shell script to do this:

LC_CTYPE=C find . -type f -exec sed -i '' '5i\
lang: en\
'
{} \;

Explanations:

I did this to edit the front-matter of books I have read, which contains metadata for each one. I want to add a language filter for my book list, so I needed to add language information to every book.

As most of the books are in English, I added this line to all of them and then edited front matter for the the Non-English books manually.