...or more legibly
I think you might be obscuring the wood with a lot of trees there! Perhaps use of the -n switch would be applicable here, either in a script or as a one-liner.
$ cat rubbish Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line8 Line9 Line10 Line11 Line12 $ perl -ne 'print if 2 .. 7;' rubbish Line2 Line3 Line4 Line5 Line6 Line7 $
The array slice method is, as you say, only suitable for small files whereas using -n when combined with last is more efficient when interested only in lines at the beginning of large files. The following examples were acting on a 2,000,000+ line log file.
# time perl -ne 'print if 5 .. 10' maillog Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... real 0m1.206s user 0m0.773s sys 0m0.432s # time perl -ne 'print if 5 .. 10; last if $. > 10' maillog Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... real 0m0.013s user 0m0.006s sys 0m0.008s #
I hope this is of interest.
Cheers,
JohnGG
In reply to Re^3: regex issue
by johngg
in thread regex issue
by pinnacle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |