I want to replace TAB
s in stdout
with semicolons, by running sed
from the ZSH shell.
I understand one can normally (in other shells?) use:
somecommand | sed 's/\t/;/g'
However, this doesn't work for me in ZSH-shell under FreeBSD. The \t
doesn't match the tabulators. Why is this? I've also tried multiple backslashes (up to 5).
This does work:
somecommand | sed 's/[TAB]/;/g'
, where [TAB]
is an actual TAB
-character, inserted by entering Ctrl-V
followed by the TAB
button on my keyboard.
Using the awk Command With the help of the awk command, we can easily convert whitespaces to TAB characters. By default, AWK uses [ \t\n]+ as Field Separator (FS) and a space character as an Output Field Separator (OFS). In the command above, we're setting the TAB character as an Output Field Separator.
Use of zsh has nothing to do with it. The \t
is a GNU extension to the regular expressions used in sed. On a BSD sed, you don't have the extensions, so have to use the literal tab.
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