Purging Logs

Many programs maintain some variety of logs. Often, much of the information in the logs is redundant or just useless. The program shown in Listing 40.7 removes all lines from a file that contain a particular word or phrase, so lines that you know are not important can be purged. For example, you might want to remove all the lines in the Apache error log that originate with your test client machine because you know those error messages were produced during testing.

LISTING 40.7 Purging Log Files

#!/usr/bin/perl# Be careful using this program!# This will remove all lines that contain a given word# Usage:  remove <word> <file>$word=@ARGV[0];$file=@ARGV[1];if ($file)  {  # Open file for reading  open (FILE, ...

Get Ubuntu Unleashed 2014 Edition: Covering 13.10 and 14.04,Ninth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.