How to globally replace strings in lines NOT starting with a certain pattern April 13, 2023 by Tarik You just need to negate the match using !: sed -i '/^##Input/! s/foo/bar/g' myfile