Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 ( #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? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-06-30 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (98 votes). Check out past polls.

    Notices?