in reply to Re^2: Matching range of text with another string in between
in thread Matching range of text with another string in between
Stevieb and GrandFather, thank you for your replies. I feel that we are heading in the right direction, but I have a few questions.
First, I should have been more thorough in my question. What you gave me does apply, but I also need the first 14 lines and the last 3 lines of the file. I wanted to make sure that you had this information.
Steveieb, I used your code but I get no results. I used your code as is, and the perl command line window got no output. If I define the output file the file gets created with no content. On a guess I changed the input file name to a nonexistent file and I got the same results, and no errors. Please pardon my noobness, and I hope that you can help :)
UPDATED: Here is what I have at the moment as I am trying to output the results to another file (the .pl file sits in the same directory as the input/output files):
use warnings; use strict; #Note that this script throws errors when pull file paths are defined. #Must be run from the path that the input/output files exist. open my $fhi, '<', 'cr835.txt' or die "$!"; open my $fho, '>', 'cr_output.txt' or die "$!"; #Prints the first 14 lines to the output file while(<>) { 1 .. 14 ? print : last; } #Prints content starting with LX* and ending with CAS* #but only if 00003 exists { local $/ = 'CAS*'; while (<$fhi>){ print $fho if /LX\*.*(?=00003$)/s; } } #Prints the last 3 lines of the file while (<F>) { $. < $lines - 3 and print while <F> } close $fhi; close $fho;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Matching range of text with another string in between
by Anonymous Monk on Apr 22, 2016 at 18:11 UTC | |
by periodicalcoder (Novice) on Apr 22, 2016 at 19:28 UTC | |
by Anonymous Monk on Apr 22, 2016 at 19:35 UTC |