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!
In reply to Extract lines from text file by JonDepp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |