To replace lines starting with this , say:
$ sed '/^this/ s/test/something/' inputfile this is to something that was for test
This will replace the word test with something with lines starting with this .
If you want to replace all instances of test with the corresponding lines, put the g option for sed:
sed '/^this/ s/test/something/g' inputfile
source share