I'm trying to substitute (with
sed) an entire line containing a specific word and the newline at the end. Here the testfile:
this # target for substitution this is a test another test?
sed 's/^this$/test/g' testfile
That works, or at least it seems so, because the newline at the end of the word
this is still there:
test # target for substitution but newline is still there this is a test another test?
Given the above, I'm also fully aware
sed can't match the newline directly (although I do recall that I could use '\n' in certain version of
sed, but that's beside the point).
I do know how to at least delete the entire word/line and the newline:
sed '/^this$/d' testfile
Except I need to substitute it instead.
How can I do this? (with