Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: pattern matching only last line of a file and then copy 10 lines above till end

by emilper (Novice)
on Oct 20, 2005 at 15:47 UTC ( [id://501706]=note: print w/replies, xml ) Need Help??


in reply to pattern matching only last line of a file and then copy 10 lines above till end

#!/usr/bin/perl -w # usefull on a unix-like system # this uses tail - displays the last lines in a file # 'tail -n 4 filename' shows the last 4 lines in a file my $file_to_check = '/tmp/test_file.txt'; my $file_to_store = '/tmp/fill_this_file.txt'; my $pattern = 'special text'; while (1) { my $last_line = `tail -n 1 $file_to_check`; if ($last_line =~ /$pattern/) { `tail -n 11 $file_to_check >> $file_to_store`; }; sleep(30 * 60); }
  • Comment on Re: pattern matching only last line of a file and then copy 10 lines above till end
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found