Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Character replacement of Textfile

    I'd like to replace "Mh:####:Mh" by "Mh" in a text file,
    where #### ranges from 0000 to 3451.

    Would you give me some tips how to use sed command to achieve this goal?

    For example, when I ran one command, sed 's/Mh/m/' Mh.txt > Mh_tr.txt, it worked.
    However, not only when there are combination of special characters with numbers, but also when there exists a numerical variable, I have no idea about this.

    Thank you in advance.

  • #2
    Sorry but its not really clear what you want to search and replace. Can you give us an example of a line you want to achieve?

    Comment


    • #3
      Originally posted by jimmybee View Post
      Sorry but its not really clear what you want to search and replace. Can you give us an example of a line you want to achieve?
      Sorry for making you confused.

      My files look like the following:
      FA file >Mh:0000:MhA1_Contig0AGTTGTTAATTTTTC
      GFF file Mh:0000:MhA1_Contig0 Freeze3 mRNA 4027 5970 + ID=MhA1

      My goal is to make these files look like the following:
      FA file >MhA1_Contig0AGTTGTTAATTTTTC
      GFF file MhA1_Contig0 Freeze3 mRNA 4027 5970 + ID=MhA1

      In other words, I will have to
      - replace Mh:0000:Mh by Mh
      - or delete Mh:0000:
      - or delete :0000:Mh

      Regardless of what numbers are in between Mh's, only "Mh" should be remained. In other words, the pattern Mh:####:Mh, where #### varies from 0000 to 3451, has to be reduced to "Mh".

      I hope my description does make sense.
      Thank you in advance for sparing your precious time.
      Last edited by syintel87; 01-02-2013, 08:32 PM.

      Comment


      • #4
        Looks like your way is ok but you need to escape the colons. This might not be the most elegant way of doing it (im far from a expert in sed and awk) but

        Code:
        sed 's/Mh\:.*\://' file > new_file
        Basically it searches for Mh:####: and removes it to leave the second "Mh"

        Hope that helps

        Comment


        • #5
          Just in case there is another ":" on that line, and you don't want to be too greedy, you might try the more conservative

          Code:
          sed 's/Mh\:[0-3][0-4][0-5][0-1]\://' file

          Comment


          • #6
            Dear jummyybee and BAMseek,

            Thank you so much!!!

            Comment

            Latest Articles

            Collapse

            • seqadmin
              Recent Advances in Sequencing Analysis Tools
              by seqadmin


              The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
              Today, 07:48 AM
            • seqadmin
              Essential Discoveries and Tools in Epitranscriptomics
              by seqadmin




              The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
              04-22-2024, 07:01 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, Today, 07:17 AM
            0 responses
            11 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 05-02-2024, 08:06 AM
            0 responses
            19 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-30-2024, 12:17 PM
            0 responses
            20 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-29-2024, 10:49 AM
            0 responses
            28 views
            0 likes
            Last Post seqadmin  
            Working...
            X