Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

by Skeeve (Vicar)
on Jul 28, 2013 at 09:02 UTC ( #1046723=note: print w/replies, xml ) Need Help??

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

If you don't want to "slurp" in the whole file at once:

my $name; my $seq; while (<DATA>) { chomp; if (s/^Name:\s*//) { $name= $_; next; } if (s/^Nucleotide Sequence:\s*//) { $seq= $_; while (<DATA>) { last if /^s*$/; chomp; $seq.= $_; } print "$name\n$seq\n\n"; } } __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


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046723]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2017-07-26 03:28 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (383 votes). Check out past polls.