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;

In reply to Re^3: Matching range of text with another string in between by periodicalcoder
in thread Matching range of text with another string in between by periodicalcoder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.