Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Shishir
    Member
    • Nov 2012
    • 22

    Parsing file to retrieve specific pattern

    I have a txt file with several rows. Each row contains several words separated by space. I want to print the values which have pattern like amenXXXXXXX (where length of X string is different in many rows). I tried grep with -o option and some other one-liners but not able to print only the words that have the pattern like amen. Indeed I want the output like:

    amen2wit
    amen3grps
    amen0qw
    amen8dbskm.....

    I will appreciate your expert suggestions.
  • rhinoceros
    Senior Member
    • Apr 2013
    • 372

    #2
    Are all amenXXXXXXX in the same column? If yes, you could just:

    cut -f N

    Where N is the column number.
    savetherhino.org

    Comment

    • dariober
      Senior Member
      • May 2010
      • 311

      #3
      Originally posted by Shishir View Post
      I have a txt file with several rows. Each row contains several words separated by space. I want to print the values which have pattern like amenXXXXXXX (where length of X string is different in many rows). I tried grep with -o option and some other one-liners but not able to print only the words that have the pattern like amen. Indeed I want the output like:

      amen2wit
      amen3grps
      amen0qw
      amen8dbskm.....

      I will appreciate your expert suggestions.
      What about this:

      Code:
      echo "no pattern
      amen
      amenXXX
      foo amenBLA foo2
      etc" > mytext.txt
      
      grep -o 'amen[^ ]*' mytext.txt
      amen
      amenXXX
      amenBLA
      How do you want to deal with the pattern occurring more than once per row, if that happens?

      Comment

      • Shishir
        Member
        • Nov 2012
        • 22

        #4
        Thanks you all !!

        Originally posted by dariober View Post
        What about this:

        Code:
        echo "no pattern
        amen
        amenXXX
        foo amenBLA foo2
        etc" > mytext.txt
        
        grep -o 'amen[^ ]*' mytext.txt
        amen
        amenXXX
        amenBLA
        How do you want to deal with the pattern occurring more than once per row, if that happens?

        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.
          Yesterday, 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, 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
        18 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-17-2026, 06:09 AM
        0 responses
        52 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-09-2026, 11:58 AM
        0 responses
        111 views
        0 reactions
        Last Post SEQadmin2  
        Working...