turbolofi has asked for the wisdom of the Perl Monks concerning the following question:
Text with similar formatting is repeated many times in the input - I'd like to print everything between "CR " and "NR" - in all occurences in the file. The code I have thus far is this:CR *FDA, 1997, GUID IND EXT REL OR BADAWY SIF, 1996, INT J PHARM, V128, P45 (more lines w. similar formatting) NR 42
use strict; use warnings; my @infile = (<>); my ($citedreferences, $line); my $n = 0; foreach $line (@infile){ if ($line =~ m{^CR .+}gsi){ do{ $n++; print $n . $line; next; } until ($line =~ m{^NR}gsi) } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing lines after regexp match until match of a different regexp
by JavaFan (Canon) on Jun 14, 2009 at 16:31 UTC | |
by turbolofi (Acolyte) on Jun 14, 2009 at 16:40 UTC |