How can I replace a word at a line which begins with a specific pattern on FreeBSD? Consider the following file contents:
this is to test
that was for test
I want to replace "test" at the line which begins with "this".
In order to perform a replacement for lines starting with this
, say:
$ sed '/^this/ s/test/something/' inputfile
this is to something
that was for test
This would replace the word test
with something
on lines starting with this
.
If you want to replace all instances of test
on the matching lines, supply the g
option to sed:
sed '/^this/ s/test/something/g' inputfile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With