Sorry..the actual tried coding is following, #!/usr/bin/perl use strict; use warnings; use Tie::File;
my ($Ltimestamp,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser, $Lhierarchy,$Lconttype); my($name,$pos,$name1,$no,$tmp,$Ltimestamp1); our $tmpp; my $file="/file/path"; open(FH,"tmp.txt") || die "can't open the file\n"; while(<FH>) { ($pos,$name1)=split; } close FH; print "position : $pos\n"; tie my @file, 'Tie::File', 'test.txt' or die $!; my $length=$#file + 1; untie @file; open(FH,"$file") || die "can't open the file\n"; seek(FH,$pos,0); while(<FH>) { ($Ltimestamp,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser, $Lhierarchy,$Lconttype)=split; if($Ltimestamp eq $name1) { #do some calculations } if($.== ($length-1)) { $tmpp=$_; } } ($Ltimestamp1,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser, $Lhierarchy,$Lconttype)=split(" ",$tmpp); $pos=tell(FH) if/^$$Ltimestamp1/; close FH; open(FH,">tmp.txt") || die "can't open the file\n"; print FH "$pos $$Ltimestamp1"; close FH; On Wed, 2007-11-07 at 10:38 +0530, sivasakthi wrote: > Hi All, > > > I have one requirement, the file content is following, it is a dynamic > file, > > 1194240905.451 105 127.0.4.56 TCP_MISS/200 2853 GET > cache_object://localhost/info - NONE/- text/plain > 1194240905.452 0 127.0.0.1 TCP_MISS/200 2853 GET > cache_object://localhost/info - NONE/- text/plain > 1194240905.452 0 127.0.0.1 TCP_MISS/200 2853 GET > cache_object://localhost/info - NONE/- text/plain > > > First time read the full file, then store byte position of the line > before the last line read and last line time stamp(eg: 1194240905.452) > in to one temporary file. > > next time first open the temporary file and get the position,time > stamp. open the file and seek the position of last time read and get > time stamp of current line, after comparing that time stamp with > already stored time stamp, if both are equal then doing some > calculation.. > > > I have tried as below, but it not works well, >