sed find an replace help

45 views
Skip to first unread message

M. Olalla Lorenzo-Carballa

unread,
Jun 20, 2016, 5:42:07 PM6/20/16
to Rescued by code: Unix & programming skills for life-scientists
Dear all

I do have a text file with several lines, each of them with the following structure:

Cluster-28302_1_TRINITY_DN11551_c0_g1_i2

Were I need to replace "Cluster-28302_1_TRINITY" for "Cluster-28302-1_TRINITY"

I have been trying to used find and replace with sed but up to know I am not able to get it right. I did the following:

cat test-sed| sed -r 's/_[0-9][0-9]*_TRINITY/.[0-9][0-9]*_TRINITY/'g

and this is what I do get:

Cluster-11746_1    Cluster-11746.[0-9][0-9]*_TRINITY_DN20997_c0_g2_i5
Cluster-11746_0    Cluster-11746.[0-9][0-9]*_TRINITY_DN20997_c0_g1_i1
Cluster-30178_1    Cluster-30178.[0-9][0-9]*_TRINITY_DN20362_c5_g1_i2
Cluster-28828_0    Cluster-28828.[0-9][0-9]*_TRINITY_DN20970_c2_g1_i1
Cluster-22499_0    Cluster-22499.[0-9][0-9]*_TRINITY_DN18016_c0_g2_i1
Cluster-22499_0    Cluster-22499.[0-9][0-9]*_TRINITY_DN18016_c0_g1_i2
Cluster-22499_0    Cluster-22499.[0-9][0-9]*_TRINITY_DN18016_c0_g1_i1
Cluster-8219_1    Cluster-8219.[0-9][0-9]*_TRINITY_DN17010_c1_g1_i3

I would be thankful if anyone could help me to find the right command to do it... I am sure it is easy and simple :S

Thanks a lot in advance

Olalla

Keith Bradnam

unread,
Jun 20, 2016, 5:47:29 PM6/20/16
to Rescued by code: Unix & programming skills for life-scientists
cat test-sed | sed 's/_TRINITY.*/-TRINITY/'

Melissa A. Wilson Sayres

unread,
Jun 21, 2016, 1:25:26 PM6/21/16
to rescue...@googlegroups.com
sed -e 's/_/-/' test-sed | sed -e 's/-TRINITY/_TRINITY/' 

--
You received this message because you are subscribed to the Google Groups "Rescued by code: Unix & programming skills for life-scientists" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rescuedbycod...@googlegroups.com.
To post to this group, send email to rescue...@googlegroups.com.
Visit this group at https://groups.google.com/group/rescuedbycode.
For more options, visit https://groups.google.com/d/optout.



--
Melissa A. Wilson Sayres, PhD
Assistant Professor of Genomics, Evolution, and Bioinformatics
The Biodesign Institute
School of Life Sciences
Arizona State University

Pedro jose Martinez

unread,
Jun 21, 2016, 1:26:21 PM6/21/16
to rescue...@googlegroups.com
Maybe that:
cat test-sed | sed -e 's/\_/-/' 

Cluster-11746-1_TRINITY_DN20997_c0_g2_i5
Cluster-11746-0_TRINITY_DN20997_c0_g1_i1
Cluster-30178-1_TRINITY_DN20362_c5_g1_i2
Cluster-28828-0_TRINITY_DN20970_c2_g1_i1


Cheers,
PJ


Pedro jose Martinez

unread,
Jun 21, 2016, 1:26:21 PM6/21/16
to rescue...@googlegroups.com
better:

cat test-sed | sed -e 's/\_/-/' | cut -d_ -f 1-2

Cheers,
PJ

Reply all
Reply to author
Forward
0 new messages