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
              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
            • seqadmin
              Current Approaches to Protein Sequencing
              by seqadmin


              Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
              04-04-2024, 04:25 PM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, Yesterday, 11:49 AM
            0 responses
            13 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-24-2024, 08:47 AM
            0 responses
            16 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-11-2024, 12:08 PM
            0 responses
            61 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-10-2024, 10:19 PM
            0 responses
            60 views
            0 likes
            Last Post seqadmin  
            Working...
            X