This should work:
use strict;
use warnings;
use autodie;
open my $fh, "<", "csvfile";
open my $op, ">", "output.txt";
my $flag;
while(<$fh>) {
if ($_ =~ /\d+\.\s*(\w+,)/) {
print $op "\n" if ($flag eq "Y");
$flag = "N";
print $op "$1";
} else {
$flag = "Y";
}
}
- Using a
while loop
read one line at a time. - Test the current line against a regex which states:
- Look for a line that starts with one or more digit
^\d+
- Followed by a literal dot
.
- Followed by zero of more spaces
\s*
. - Using a captured group for
(\w+,)
to capture any word followed by a,
.
- Look for a line that starts with one or more digit
- Print the line if it matches the regex.