This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Using awk or sed to edit a column in a gtf file

Dear all,

I have a gft file and I want to remove a cenrtaind word in a certain column:

In this case I want to remove in the second column "mRNA." and just to keep CA01g00010 in this column, could you help me with this?

Pepper1.55ch01  mRNA.CA01g00010 63209   63880

I would like this output

Pepper1.55ch01   CA01g00010 63209   63880

Best

awk sed gft linux

In the case provided it can also be: sed "s/\tmRNA\./\t/g" example.gtf.

1 answer

awk -v OFS="\t" -v FS="\t" '{ $2=gensub("^mRNA.", "", 0, $2); print $0; }' your_file > your_modified_file

Edit: removed tab-separated assumption, as I just saw it should treat a gtf, which we all know is tab-separated.

another awk solution:

$ awk -v OFS="\t" -F "\t" '{sub("^[a-zA-Z]+\.","",$2)}1' test.txt
$ awk -v OFS="\t" -F "\t" '{$2=substr($2,6)}1' test.txt
Pepper1.55ch01  CA01g00010  63209   63880

with gawk installed:

 $ awk -v OFS="\t" -F "\t" '{sub("^[a-zA-Z]{4}.","",$2)}1' test.txt

This worked awesome for me thank you!

thank you, I could remove mRNA part

Log in to answer this question.