Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Extracting multiple rows in a text file with a regex.

by 2teez (Priest)
on Jul 28, 2013 at 09:51 UTC ( #1046726=note: print w/ replies, xml ) Need Help??


in reply to Extracting multiple rows in a text file with a regex.

If I may add this. You can step through your data line by line getting what you want, then to get all your "Nucleotide Sequence", since you have a "blanck" line used as delimiter, then you could use perl "flip-flop" operator (..) as it is called like so:

use warnings; use strict; while(<DATA>){ if(/Name:\s+?(.+?)$/){ print $1,$/; } if(/Nucleotide Sequence/../^\s*$/){ # use "flip-flop" operator s/.*:\s+?//; # remove the Nucleotide Sequence to :,then print print } } __DATA__ GeneID: 1002 Name: cadherin 4, type 1, R-cadherin (retinal) Chromo: 20 Cytoband: 20q13.3 Nucleotide Sequence: atgaccgcgggcgccggcgtgctccttctgctgctctcgctctccggc acagcgagactggagatatcgtcacagtggcggctggcctggaccgagagaaagttcagcagtacacag cagcttgcgcatcctgtacctggaggccgggatgtatgacgtccccatcatcgtcacagactctggaaa GeneID: 10077 Name: tetraspanin 32 Chromo: 11 Cytoband: 11p15.5 Nucleotide Sequence: atggggccttggagtcgagtcagggttgccaaatgccagatgctggtc GeneID: 10078 Name: tumor suppressing subtransferable candidate 4 Chromo: 11 Cytoband: 11p15.5 Nucleotide Sequence: atggctgaggcaggaacaggtgagccgtcccccagcgtggagggcgaa
Produces ..
cadherin 4, type 1, R-cadherin (retinal) atgaccgcgggcgccggcgtgctccttctgctgctctcgctctccggc acagcgagactggagatatcgtcacagtggcggctggcctggaccgagagaaagttcagcagtacacag cagcttgcgcatcctgtacctggaggccgggatgtatgacgtccccatcatcgtcacagactctggaaa tetraspanin 32 atggggccttggagtcgagtcagggttgccaaatgccagatgctggtc tumor suppressing subtransferable candidate 4 atggctgaggcaggaacaggtgagccgtcccccagcgtggagggcgaa

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: Extracting multiple rows in a text file with a regex.
Select or Download Code
Re^2: Extracting multiple rows in a text file with a regex.
by Skeeve (Vicar) on Jul 29, 2013 at 06:05 UTC

    I'd move the flip-flop operator to the top of the loop. Testing for "Name", while the "flip" didn't "flop" is useless.

    Additionally I'd either make the second "if" an "elsif" or leave the "if" block with a "next" in order not to check more than required.


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (17)
As of 2014-10-23 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (129 votes), past polls