0

I have a tab-separated file which looks as follows:

GCF_000014165.1_ASM1416v1.dist_nbr_anntn        WP_011558474.1  1155234 1156286 44173   polyketide synthase [Mycobacterium]
GCF_000014165.1_ASM1416v1.dist_nbr_anntn        WP_011558475.1  1156298 1156807 12      isoprenylcysteine       carboxyl        methyltransferase       [Mycobacterium]
GCF_000014165.1_ASM1416v1.dist_nbr_anntn        WP_011558476.1  1156804 1157820 -3      NAD(P)/FAD-dependent    oxidoreductase  [Mycobacterium]

How do I replace tabs from column 6 to the last column with spaces?

The output should look as follows:

GCF_000014165.1_ASM1416v1.dist_nbr_anntn        WP_011558474.1  1155234 1156286 44173   polyketide synthase [Mycobacterium]
GCF_000014165.1_ASM1416v1.dist_nbr_anntn        WP_011558475.1  1156298 1156807 12      isoprenylcysteine carboxyl methyltransferase [Mycobacterium]
GCF_000014165.1_ASM1416v1.dist_nbr_anntn        WP_011558476.1  1156804 1157820 -3      NAD(P)/FAD-dependent oxidoreductase [Mycobacterium]
1

With GNU sed, it's as simple as:

sed 's/\t/ /6g' file

The s command can be followed by zero or more of the following flags:

g 

Apply the replacement to all matches to the regexp, not just the first.

number 

Only replace the numberth match of the regexp.

interaction in s command Note: the POSIX standard does not specify what should happen when you mix the g and number modifiers, and currently there is no widely agreed upon meaning across sed implementations. For GNU sed, the interaction is defined to be: ignore matches before the numberth, and then match and replace all matches from the numberth on.

See sed, a stream editor: The s Command

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.