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

OSX's sed only understands \t in the pattern, not in the replacement doesn't understand \t at all, since it's essentially the ancient 4.2BSD sed left over from 1982 or thenabouts. Use a literal tab (which in bash and vim is Ctrl+V, Tab), or install GNU coreutils to get a more reasonable sed.


Try: Ctrl+V and then press Tab.


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'

Tags:

Macos

Regex

Sed