Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: breaking up very large text files - windows

by dga (Hermit)
on Jul 28, 2003 at 20:32 UTC ( #278606=note: print w/replies, xml ) Need Help??

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 $_; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://278606]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2021-06-18 04:58 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (87 votes). Check out past polls.