Using sed on Mac OS 10 to replace tabs in text files

I searched here for quite some time, and although I found very good information, there is nothing needed in my problem. Short-n-sweet, I use sed on Mac OS 10.11 to try and replace the tab character with a pipe character. All the information I found on this syntax may work on other platforms, but not on Mac OS 10.11. I know sed works on 10.11 since I can replace normal standard characters all day long and even some punctuation marks like comma. And yes, I tried to use \t. The sed line I found that works with standard characters is this:

sed -i '' -e 's/,/|/g' /Users/username/Desktop/TABs2PIPE.txt

When I use \tinstead of ,in the line above, it just replaces all lowercase tin the file.

So, any other Macheads that got this at work, I would really appreciate some help, thanks in advance.

+6
source share
3 answers

OSX sedis a BSD derivative; this line was sednever taken \tas a symbol for the symbol TAB, IIRC. If your shell bash(which is the default for OSX) try this instead:

sed -i '' -e $'s/\t/|/g' file_to_process.txt

$'...'- extension of bash; this word '...', but C-type backslash escape images are interpreted internally. From the bash manpage:

$'string' . , ANSI C.

, sed -e s/ /|/g, TAB, .

bash, , , , control-V, TAB.

+4

sed -T, , , !

:

sed -i s/\<CTRL-V><TAB>/\|/g text.txt

< CTRL-V > <TAB> .

+1

, , , -i stdin. -i?

0

Source: https://habr.com/ru/post/1659216/


All Articles