I'm a bit of a beginner too but here are my thoughts anyway.
It sounds to me like the only reason you are keeping the first line may be
because you are worried that the file will diappear if you don't.  This is
not necesarily the case so I'm thinking something like the following example
would work, tested this on linux o.k. don't know about others:
#!/usr/bin/perl -w
$in_file = "in.txt";
$out_file = "out.txt";
open(IN, "+<$in_file") or die "$in_file: $!\n"; # open input read/write
open(OUT, ">>$out_file") or die "$out_file: $!\n"; # open output append
print OUT <IN>; # in essence, copy input file to output file
truncate(IN, 0); # make the input file blank but don't remove it

One thing to think about is file locking issues if there is the potential
for log entries being written to the input file at 11:59 when you run this.
There is "flock" command but I think it only works if all other programs
cooperate.
Again I'm a bit green with Perl so there is probably and alternate/better
way.

Ian D. Mitchell
System Consultant
Applications Development & Support
Corporate Information Systems
David Thompson Health Region

> -----Original Message-----
> From: Nichole Bialczyk [mailto:[EMAIL PROTECTED]]
> Sent: June 1, 2001 3:17 PM
> To: [EMAIL PROTECTED]
> Subject: Re: append a file to another file - delete
> 
> 
> so how do i delete the lines that i read in? (keeping the 
> first one so 
> that the file still exists)
> 
> On Fri, Jun 01, 2001 at 02:08:25PM -0700, Paul wrote:
> > 
> > --- Nichole Bialczyk <[EMAIL PROTECTED]> wrote:
> > > to be more specific, i want to do this: read and delete all of the
> > > lines  from a log file, except for the first one.
> > 
> >  open IN, $file or die "$file:$!";
> >  <IN>;        # throw away first line;
> >  print <IN>;  # print the rest of the file.
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Get personalized email addresses from Yahoo! Mail - only $35 
> > a year!  http://personal.mail.yahoo.com/
> 

Reply via email to