This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Sed problem to change names

Hi,

I want to use 'Sed' to change the names in both sequences and annotation files. Such as change

scaffold1_size2426064 exon
scaffold2_size1571916 exon
scaffold3_size1509833 gene
scaffold4_size1453470
scaffold5_size1243770
scaffold6_size1253778
scaffold7_size1219719
scaffold8_size1223566
scaffold9_size1121364
scaffold10_size1060754

...... to

scaffold1 exon
scaffold2 exon
scaffold3 gene
scaffold4
scaffold5
scaffold6
scaffold7
scaffold8
scaffold9
scaffold10

Delete '_'and the following things. I tried sed 's/_size*//g' file but it didn't work. And I don't want to use blank to instead those things in my annotation file. Does anybody know how to do this? Thanks.

Zhang

sequence

Hello HZZ0036!

We believe that this post does not fit the main topic of this site.

This is just Unix. Search StackOverflow please.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

2 answers

sed 's/_[^ ]*//' input.txt

You can try sed 's/_size.*[0-9]//g'

$ echo 'scaffold1_size2426064 exon' | sed 's/_size.*[0-9]//g'
scaffold1 exon

Log in to answer this question.