As for the regex part, I'm not sure since I'm not familiar with using the combo of regexes and the range operator. However, I'd advise going a different route than using the substr command to find the critical data that your trying to key in on. It looks like you're data is somewhat columnar, which means that using split /\s+/ can be used to create an array with each column stored in a different element.
The code below is how I would approach the problem. It kind of looks like you're planning to add more code to do other stuff, which means that the code below would probably need to be modified to fit in with your bigger plan.
Code:
use strict; use warnings; my $infile = "data.txt"; my $outfile = "peptest.txt"; open(DATA,"<",$infile) || die "Unable to open file '$infile': $!\n"; my $file; # Slurp in the file into memory { local $/; $file = <DATA>; } close(DATA); open(OUTPUT,">",$outfile) || die "Unable to open file '$outfile': $!\ +n"; my ($section) = ($file =~ m/(NAME.*)ADJ/is); my (@lines) = split /\n/,$section; my $i = 0; foreach my $line (@lines) { if ($line =~ m/1235114182/) { my (@cols) = split /\s+/,$line; if ($cols[12] eq "0.00") { print OUTPUT "$lines[$i]\n$lines[$i+1]\n"; } } $i++; } close(OUTPUT);
Output file:
12351141821118 111809 23 001 71010 26 31.00 0.00 + 0.00 0.00 CO-18 31.00 0.00 + N347 12351141821118 111809 23 001 74150 26 199.00 0.00 + 0.00 0.00 CO-18 199.00 0.00 + N347 12351141821118 111809 23 001 72192 26 182.00 0.00 + 0.00 0.00 CO-18 182.00 0.00 + N347
In reply to Re: Regex Not Grabbing Everything
by dasgar
in thread Regex Not Grabbing Everything
by JonDepp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |