How can I insert a tab character with sed on OS X?

I have tried:

echo -e "egg\t  \t\t salad" | sed -E 's/[[:blank:]]+/\t/g'

Which results in:

eggtsalad

And...

echo -e "egg\t  \t\t salad" | sed -E 's/[[:blank:]]+/\\t/g'

Which results in:

egg\tsalad

What I would like:

egg salad

Solution 1:

Try: Ctrl+V and then press Tab.

Solution 2:

Use ANSI-C style quoting: $'string'

sed $'s/foo/\t/'

So in your example, simply add a $:

echo -e "egg\t  \t\t salad" | sed -E $'s/[[:blank:]]+/\t/g'