Use the perl documentation installed on your machine with the binary.<br>
<br>
perldoc perlrun<br>
<br>
describes all the command line options, including -p, -n, -i. You'll
see the file is processed line by line. Of course the system buffers
are the controlling factor for memory usager, if your lines are an
ordinary length of 80 or so characters, since the buffers are a few KB
in size<br>
<br>
<br><br><div class="gmail_quote">On Thu, Oct 1, 2009 at 9:53 PM, Viktor Pavlenko <span dir="ltr"><<a href="mailto:vvp@cogeco.ca">vvp@cogeco.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">>>>>> "MK" == Madison Kelly <<a href="mailto:linux@alteeve.com">linux@alteeve.com</a>> writes:<br>
<br>
>> perl -i -ne 'print if $. > 20' file<br>
<br>
</div> MK> Where 'if' is the input file handle? I've not played with<br>
MK> '$.'...<br>
<br>
$. is the line number, starting from 1. `if' is just an `if', you can<br>
write it traditional way: if ($. > 20) { print }. It says to print $_<br>
(omitted) if the line number is greater than 20. It's a perl<br>
one-liner, it allows you to read one line at a time and put it in $_,<br>
-n means don't print it, and -i tells perl to edit the file in place<br>
(all tmp file business is taken care of). What follows -e is the<br>
script to execute.<br>
<br>
MK> 'If this works it'd be the pure-perl way I was hoping<br>
MK> for. Do you know if this still reads the whole file into<br>
MK> memory at once? My biggest concern, even more than speed, is<br>
MK> that this may need to be done on files larger than available<br>
MK> RAM.<br>
<br>
I'm sure it reads a line at a time and then throws it away, so no<br>
worries about memory. Your point about inefficiency of reading &<br>
copying remains valid.<br>
<br>
HTH<br>
<br>
--<br>
<font color="#888888">Viktor<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</div></div></blockquote></div><br>