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
Press and hold your option key, then type 0009 (zeroes). This is the Unicode sequence for the tab control character.
One way to make the GNU version of the SED to work on the Mac OS X, is to directly install the gnu-sed along with the default names which will assure you that you won't have to run different commands on both the operating systems.
Use Ctrl+V (or Control+V on a Mac) and then the tab key. That will put a literal tab on the command line, which can be useful if (like me) you need to grep for a single character in a field in a tab delimited text file.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With