JonDepp has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I have been looking at this for a few days and cannot see an answer so I humbly ask your opinion.
I have a data file that is laid out like the following:
DOE JOHN 123 DENIRO ROBERT 123 123 123 CUBE ICE 123 123
There are names followed by lines that have numbers in them that correspond to each name. The name line can be followed by any number of number lines. I want to extract the name and its corersponding number lines if the name matches and/or the number lines match some user input.
The following code is where I am starting:
use strict; use warnings; open OUTPUT, "> info.txt" or die $!; print "What file do you want parsed? "; my $file1 = <STDIN>; print "Name: "; chomp (my $name = <STDIN>); open FILE, "$file1"; while (<FILE>) { if (/$name/.../\n/) { print OUTPUT $_ until ($_ ne\d+/); } }
I would be most grateful for any guidance. Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extract lines from text file
by toolic (Bishop) on Jan 31, 2011 at 19:51 UTC | |
|
Re: Extract lines from text file
by jethro (Monsignor) on Jan 31, 2011 at 22:48 UTC |