in reply to Print some lines in a range

-p + <>???
-p + print???

Your code should be

perl -e"@lines=<>; print @lines[41900..50000];" data02.log > data03.lo +g

As for your question,

perl -ne"next if $.<41901; print; exit if $.==50001;" data02.log > dat +a03.log

($. is one-based while arrays are zero-based. That's why I changed the indexes by one.)

Replies are listed 'Best First'.
Re^2: Print some lines in a range
by ranrodrig (Novice) on Mar 06, 2010 at 04:15 UTC

    Folks thanks a lot for your answers you saved my Soul & the best solution is the one that ikegami post

    time perl -ne"next if $.<41901; print; exit if $.==50001;" data02.log > data03.log

    real 0m0.26s

    The next one also works but is slower to run

    time perl -ne "print if 41901 .. 50001" data02.log > data03.log

    real 0m33.21s

    An this one runs too but it takes a lot of time to run

    time perl -e"@lines=<>; print @lines[41900..50000];" data02.log > data03.log

    real 1m9.42s

      The first stops when enough has been read. Both the second and the third read the entire file. The difference is that the third loads the entire file into memory. And since we're talking about at least 50,000 lines, you might be running into swapping issues. The third definitely has a lot more memory allocations (one per line) than the second (almost none), and those aren't cheap.