regexsedoctopress

How to use sed to add a new line of text after matched pattern?


I'm trying to add one more line to my posts in Octopress. It's

comments: true

I have about 200 posts so I would like to do it in one go. I was testing with this but it doesn't seem to work.

echo title: 'Blah Blah.' | sed "s/'title: .*'/'title: .*'\n'comments: true'\n/g"

The result I want is.

title: 'Blah Blah.'
comments: true

Solution

  • Does this work?

    echo title: 'Blah Blah.' | sed "s/'title: .*'/'\1\r\ncomments: true'\n/g"
    

    @BigOldTree 's suggestion:

    echo title: 'Blah Blah.' | sed "/title: .*/a comments: true"