in reply to Simulating UNIX's "tail" in core Perl

perl -wn000e '$start=1034; $end=1047; $pre=$start-1; $len=$end-$start+ +1; print / (?:.*\n){$pre} ( (?:.*\n){$len} ) /mx ' <<filename>>


p

Replies are listed 'Best First'.
Re: Re: Simulating UNIX's "tail" in core Perl
by jorg (Friar) on Mar 07, 2001 at 14:37 UTC
    right, it's 10am here in London so i'm not really with it yet. Would someone care to explain this post to me ?

    tnx Jorg
      "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