How to replace multiple blank spaces with tab on a mac

Viewed 3517

I am trying to replace blank spaces with one tab in a fasta file, and then replace those tabs with new lines. It turns out that \t and \n do not work on mac terminal.

I have found that the \t is control+v tab, which is a major pain to type in the terminal and not conducive to copy/pasting scripts.

I have not been able to find a mac command equivalent to \n for a newline.

Desired outcome for replacing multiple blank spaces with tabs:

string1  string2
string1 <tab> string2

I have used

sed 's/  /control+v <tab>/g <filename

This works but is a pain because I need to know the exact number of consecutive blank spaces and I need to do the control+v tab deal.

For replacing each tab with a new line to get:

string1
string2

I have tried a similar method using control+v return, but that does not give the desired outcome.

Thanks in advance for you help.

3 Answers
Related