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); }
|
|---|