I found how to insert a line after a certain line in bash

sed -i '/oh-my-zsh.sh/aplugins=(git symfony2)' ~/.zshrc


source $ZSH/oh-my-zsh.sh
plugins=(git symfony2)

But I would like to insert my line before source $ZSH/oh-my-zsh.sh.

How is it possible?


The 'a' in '...sh/aplug..." is for 'add' and puts the new text after the search pattern. Replace it with 'i' for 'insert' to put the text before the search pattern. Like this:

sed -i '/oh-my-zsh.sh/iplugins=(git symfony2)' ~/.zshrc'

This answer and MUCH more can be found at: Sed - An Introduction and Tutorial by Bruce Barnett.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.