As others have noted, sed is not suitable for this task. This, of course, is possible, here is one example that works on separate lines with spaces separated by spaces:
echo "She sells sea shells by the sea shore" | sed 's/ /\n/g' | sed '/^[Ss]h/ s/[^[:punct:]]/./g' | sed ':a;N;$!ba;s/\n/ /g'
Output:
... sells sea ...... by the sea .....
The first "sed" replaces the spaces with newlines, the second with a period, the third removes the newlines as shown in this answer .
If you have unpredictable word separators and / or paragraphs, this approach will soon become unmanageable.
Edit - Multiline Alternatives
Here's one way to handle multi-line input inspired by Kent's comments (GNU sed):
echo " She sells sea shells by the sea shore She sells sea shells by the sea shore, She sells sea shells by the sea shore She sells sea shells by the sea shore She sells sea shells by the sea shore She sells sea shells by the sea shore " | # Add a \0 to the end of the line and surround punctuations and whitespace by \n sed 's/$/\x00/; s/[[:punct:][:space:]]/\n&\n/g' | # Replace the matched word by dots sed '/^[Ss]h.*/ s/[^\x00]/./g' | # Join lines that were separated by the first sed sed ':a;/\x00/!{N;ba}; s/\n//g'
Output:
... sells sea ...... by the sea ..... ... sells sea ...... by the sea ....., ... sells sea ...... by the sea ..... ... sells sea ...... by the sea ..... ... sells sea ...... by the sea ..... ... sells sea ...... by the sea .....
source share