Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syintel87
    Member
    • Dec 2012
    • 81

    #1

    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.
  • jimmybee
    Senior Member
    • Sep 2010
    • 119

    #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

    • syintel87
      Member
      • Dec 2012
      • 81

      #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

      • jimmybee
        Senior Member
        • Sep 2010
        • 119

        #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

        • BAMseek
          Senior Member
          • Apr 2011
          • 124

          #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

          • syintel87
            Member
            • Dec 2012
            • 81

            #6
            Dear jummyybee and BAMseek,

            Thank you so much!!!

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
              by SEQadmin2



              Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

              Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
              ...
              10-14-2026, 09:55 AM
            • SEQadmin2
              New Genomics Technologies Take Aim at Long-Standing Limits
              by SEQadmin2


              Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

              We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
              ...
              09-28-2026, 10:25 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, 10-22-2026, 11:13 AM
            0 responses
            35 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-22-2026, 10:48 AM
            0 responses
            28 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-15-2026, 10:52 AM
            0 responses
            41 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-14-2026, 05:39 AM
            0 responses
            45 views
            0 reactions
            Last Post SEQadmin2  
            Working...