2

I had file1:

MSTRG.10807.1   0.494311896511595   MID    0.423993026403461 2.39379412548345   1.99703339651136
MSTRG.10884.1   0.365770947942799   EARLY  1.46416917664929   1.16816186543633   0.689075392478972
MSTRG.10958.1   0.52855355823638    MID    0.885493751836316  2.28463841550375   1.26867555157512

I used command the sed 's/ /,/g' file1 > file2 and this produced file2:

MSTRG.10807.1,,,0.494311896511595,,,MID,,,,0.423993026403461,,2.39379412548345,,,1.99703339651136
MSTRG.10884.1,,,0.365770947942799,,,EARLY,,1.46416917664929,,,1.16816186543633,,,0.689075392478972
MSTRG.10958.1,,,0.52855355823638,,,,MID,,,,0.885493751836316,,2.28463841550375,,,1.26867555157512

But I want a tab-delimited file.

6

If you want the tab character, use \t as the replace pattern instead of ,.

If you want just one tab (or comma) to replace multiple spaces, add \+ after the space:

sed 's/ \+/\t/g' file1 > file2
9

Use tr:

tr -s ' ' '\t' < file1 > file2

-s, --squeeze-repeats
replace each sequence of a repeated character that is listed in the last specified SET, with a single occurrence of that character

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.