http://www.perlmonks.org?node_id=278606


in reply to breaking up very large text files - windows

One possibility is to seek to the end of the file and work back from there.

If you don't need exactly 1000 lines another possibility is to seek to some distance from the end say 1k bytes, read and ignore one line (probably part of a line) then output the rest of the file to your smallfile. Of course if the log messages are a fixed length then the math to get 1000 lines from the end is easy to do. Though since you want to tail the files then some number of kilobytes then reading forward to the next linebreak to get the start of a line should probably work and quickly to boot.

open(BIG, "name_here"); open(SMALL, "other_name_here"); seek(BIG, -1024, 2); my $junk=<BIG>; #pitch to end of current line while(<BIG>) { print SMALL $_; }