Assume that the word child
had to be replaced with son
in a file consisting of sentences (not a list of words).
It isn't a straight string replacement; for example, the following should not happen:
children
should not be changed to sonren
but the following should happen:
child.
should be changed to son.
child!
should be changed to son!
Basically, the text that is to be replaced must be an independent word and the word separators must be preserved.
How can this be done without hard-coding for every possible word separator?
sed 's/\<child\>/son/g'
orsed 's/\bchild\b/son/g'
– αғsнιη Jan 24 '18 at 14:25