"Give me lines 1034 through 1047 of the file."
perl -wn000e # -n read file, 000 set $/ (input separator) to n +il # hence, read whole file into $_ '$start = 1034; # number of the line to start printing +at $end = 1047; # number of the line to end printing at $pre = $start - 1; # the number of lines to skip before pr +inting $len = $end - $start + 1; # the number of lines to print print / (?: # don't remember this () in $1..$n .*\n # all chars up to a newline and the \n ){$pre} # pre number of times ( # remember this (return it as first el of +list) (?: # but don't remember this part as 2nd elem +ent .*\n # match a line up to and including \n ){$len} # number-of-lines-to-print times ) # return as single (multi-line) value /mx' # /m: don't let '.' match \n (may not be n +ecessary)


p

In reply to Re: Re: Re: Simulating UNIX's "tail" in core Perl by petral
in thread Simulating UNIX's "tail" in core Perl by gryphon

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.