Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • AnushaC
    Member
    • Sep 2013
    • 78

    In BASH splitting into substring based on pattern(or) last occurrence of a digit (**)

    Hi,

    I am trying to split string into substring based on pattern in bash (or) based on last occurance of a digit
    y=`echo "AB097865ATCTCTAGCAGTGGCGCCCGAACAGGGCACGCGAA"|grep "[AT|AC|AG|AA|CT|CC|CA|CG|GT|GC|GA|GG|TT|TC|TA|TG]"`

    I tried to do like this but failed

    I want to get the substring after the last digit and
    result should be

    ATCTCTAGCAGTGGCGCCCGAACAGGGCACGCGAA

    Thanks so much for help

    Anusha
  • Richard Finney
    Senior Member
    • Feb 2009
    • 701

    #2
    ugly way ... pick a character not in the input, in this case '_' ...
    y=`echo "AB097865ATCTCTAGCAGTGGCGCCCGAACAGGGCACGCGAA" | sed 's/[0-9]/_/g' | awk -F "_" '{print $NF}'`
    echo $y

    better (I think) ..

    y=`echo "AB097865ATCTCTAGCAGTGGCGCCCGAACAGGGCACGCGAA" | sed 's/.*[0-9]//g' `
    echo $y
    Last edited by Richard Finney; 03-26-2016, 03:27 PM.

    Comment

    • westerman
      Rick Westerman
      • Jun 2008
      • 1104

      #3
      I have always thought that invoking sed/awk or any of the other programming tools for work inside Bash is ..., well, cheating. Useful in the practical "let us get stuff done" sense but at that point one might as just well write Perl or Python, etc. code. 'sort', 'cut', 'grep' are valid tools within a script since they are not really programming.

      Anyway to the OP, look at:



      It has an example of what you want to do.
      Last edited by westerman; 03-28-2016, 12:44 PM. Reason: spelling

      Comment

      • tomc
        Member
        • Feb 2011
        • 29

        #4
        Variable substitution

        foo="AB097865ATCTCTAGCAGTGGCGCCCGAACAGGGCACGCGAA"
        echo ${foo##*[0-9]}
        ATCTCTAGCAGTGGCGCCCGAACAGGGCACGCGAA
        Last edited by tomc; 03-28-2016, 01:24 PM. Reason: what it is

        Comment

        Latest Articles

        Collapse

        • GATTACAT
          Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
          by GATTACAT
          Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
          07-01-2026, 11:43 AM
        • SEQadmin2
          Nine Things a Sample Prep Scientist Thinks About Before Sequencing
          by SEQadmin2


          I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

          Here are nine questions we think about, in roughly the order they matter, before...
          06-18-2026, 07:11 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, Yesterday, 11:08 AM
        0 responses
        6 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-30-2026, 05:37 AM
        0 responses
        11 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-26-2026, 11:10 AM
        0 responses
        19 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-17-2026, 06:09 AM
        0 responses
        53 views
        0 reactions
        Last Post SEQadmin2  
        Working...