Hey there. So a common trick is to use the $/ perl variable. It enables you to read input data record-by-record instead of by line. When set to "" the input will be read as blocks that are separated by empty lines. So, with the input file you provided:
Produces:use strict; use autodie; open my $FH, '<', 'test.dat'; open my $FH2, '>', 'seq.dat'; for (do {local $/ = ""; <$FH>}) { my ($name) = /Name:\s+(.+)/; my ($seq) = /Nucleotide\sSequence:\s(.*)/xms; $seq =~ s/\n//g; print $FH2 "$name\n$seq\n\n"; }
cadherin 4, type 1, R-cadherin (retinal) atgaccgcgggcgccggcgtgctccttctgctgctctcgctctccggcacagcgagactggagatatcgt +cacagtggcggctggcctggaccgagagaaagttcagcagtacacagcagcttgcgcatcctgtacctg +gaggccgggatgtatgacgtccccatcatcgtcacagactctggaaa tetraspanin 32 atggggccttggagtcgagtcagggttgccaaatgccagatgctggtc tumor suppressing subtransferable candidate 4 atggctgaggcaggaacaggtgagccgtcccccagcgtggagggcgaa
In reply to Re^3: Extracting multiple rows in a text file with a regex.
by Loops
in thread Extracting multiple rows in a text file with a regex.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |