As noted by others, sed is not well suited for this task. It is of course possible, here's one example that works on single lines with space separated words:
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 spaces by newlines, the second does the dotting, the third removes newlines as shown in this answer.
If you have unpredictable word separators and/or paragraphs, this approach soon becomes unmanageable.
Edit - multi-line 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 .....