JonDepp has asked for the wisdom of the Perl Monks concerning the following question:
Hey all, I am new to perl and am writing a text parser to wittle a large text file down and extract peices I need to an output file. I have code written that extracts the part I need but it is also extracting everything else in the file. It also seems to be running through the file a few times as information is repeated in my output file. Here is my code:
use strict; use warnings; open TEST, "tests.txt" or die $!; open OUTPUT, "> output1.txt" or die$!; my @file = grep/SUBSCRIBER/../NATIONAL/, <TEST>; my $line; foreach $line(@file) { if ($line=~m/A1/) { print OUTPUT @file; } } close TEST; close OUTPUT;
I want the output file to just have the text located between SUBSCRIBER and NATIONAL if there is an A1 code on one of the lines.
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Text Extraction
by toolic (Bishop) on Feb 05, 2010 at 15:31 UTC | |
by JonDepp (Novice) on Feb 08, 2010 at 19:16 UTC | |
by JonDepp (Novice) on Feb 05, 2010 at 16:44 UTC | |
by planetscape (Chancellor) on Feb 06, 2010 at 15:04 UTC | |
|
Re: Text Extraction
by holli (Abbot) on Feb 05, 2010 at 15:01 UTC | |
by JonDepp (Novice) on Feb 05, 2010 at 15:14 UTC | |
|
Re: Text Extraction
by jwkrahn (Abbot) on Feb 05, 2010 at 17:06 UTC | |
by JonDepp (Novice) on Feb 05, 2010 at 21:17 UTC |