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

            • kinpict.com
              Reply to 16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
              by kinpict.com
              The part about this topic feels surprisingly grounded, and the details on the page is the bit that made me slow down. I’d keep <a href="https://kinpict.com/">ai family photo generator</a> bookmarked for later.
              Today, 06:37 PM
            • SEQadmin2
              16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
              by SEQadmin2





              NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
              10-30-2026, 06:46 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, 11-12-2026, 07:59 AM
            0 responses
            27 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 11-05-2026, 09:25 AM
            0 responses
            35 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 11-03-2026, 11:54 AM
            2 responses
            56 views
            0 reactions
            Last Post kinpict.com  
            Started by SEQadmin2, 10-28-2026, 09:57 AM
            0 responses
            175 views
            0 reactions
            Last Post SEQadmin2  
            Working...