🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.perl.misc
Article #249

Re: reverse file reading

#249
From: Christopher A Stoner
Date: Wed, 04 Oct 1995 00:00
59 lines
2805 bytes
In article <44spkk$ipv@rs3.rz.uni-hohenheim.de>, pvr  <pvr> wrote:
|Hi,
|is there an easy way to read a file in reverse order (like tail -x does).
|My problem is that I just need the file contents starting at a pattern
|very near the end of a really long file (yes, it's an access_log :-)     
|and I was wondering if it wouldn't be possible to begin at the end of the
|file to speed up my prog.                                           
|Regarding how quick "tail -1 access_log" is I can't believe this         
|scans the whole file. So, is there a perl solution, too ?
|
|If you have any reply, please send me an E-mail, cause our news server
|deletes the files rather quick (at least quicker than I read them :-(.
|
|Thanks.
|

To: pvr
Subject: Re: reverse file reading
Newsgroups: comp.lang.perl.misc,fj.lang.perl,de.comp.lang.perl
In-Reply-To: <44spkk$ipv@rs3.rz.uni-hohenheim.de>
Organization: State University of New York at Buffalo/Computer Science
Cc: 
Bcc: 

In article <44spkk$ipv@rs3.rz.uni-hohenheim.de> you write:
|Hi,
|is there an easy way to read a file in reverse order (like tail -x does).
|My problem is that I just need the file contents starting at a pattern
|very near the end of a really long file (yes, it's an access_log :-)     
|and I was wondering if it wouldn't be possible to begin at the end of the
|file to speed up my prog.                                           
|Regarding how quick "tail -1 access_log" is I can't believe this         
|scans the whole file. So, is there a perl solution, too ?
|
|If you have any reply, please send me an E-mail, cause our news server
|deletes the files rather quick (at least quicker than I read them :-(.
|
|Thanks.
|


Well, you can view a file in reverse:

@input = reverse <>;

foreach $_ (@input) {

	if (/search pattern/){
		do stuff here
	}
}

hope it help. 

Might also consider the seek command, you could jump forward several K of file
at a time before you start reading. Ask me if you want some help with that.

	-Chris. (stoner@cs.buffalo.edu)
        http://www.cs.buffalo.edu/~stoner
Technical Details
Message-ID: <44uagq$9tk@azure.acsu.buffalo.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <44spkk$ipv@rs3.rz.uni-hohenheim.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1043e7,54d2c575875f4961
X-Google-Attributes: gid1043e7,public
X-Google-Thread: 1133f4,54d2c575875f4961
X-Google-Attributes: gid1133f4,public
X-Google-Thread: fa0ae,54d2c575875f4961
X-Google-Attributes: gidfa0ae,public
From: stoner@cs.buffalo.edu (Christopher A Stoner)
Subject: Re: reverse file reading
Date: 1995/10/04
Message-ID: <44uagq$9tk@azure.acsu.buffalo.edu>
X-Deja-AN: 117026292
references: <44spkk$ipv@rs3.rz.uni-hohenheim.de>
organization: State University of New York at Buffalo/Computer Science
nntp-posting-user: stoner
newsgroups: comp.lang.perl.misc,fj.lang.perl,de.comp.lang.perl