Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed replace literal TAB

Tags:

sed

freebsd

I want to replace TABs 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.

like image 779
poplitea Avatar asked Dec 06 '11 13:12

poplitea


People also ask

How do I change tab space in Linux?

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.


1 Answers

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.

like image 175
Michael J. Barber Avatar answered Nov 27 '22 14:11

Michael J. Barber