I\'m trying to detect a pattern that has three parts:
I
Just matching space, then m or t, then space or newline won't catch cases with punctuation, e.g. a missing ' in "please don t!". A more general solution is to use word boundaries instead:
echo "i m sure he doesn t test test don t." | sed 's/ \([mt]\)[[:>:]]/\1/g'
The funky [[:>:]] is required on OS X (which I use), see Larry Gerndt's answer to sed whole word search and replace. On other sed flavors you may be able to use \b (any word boundary) or \> instead.
# example with word boundary
echo "i m sure he doesn t test test don t." | sed 's/ \([mt]\)[[:>:]]/\1/g'
im sure he doesnt test test dont.