[Gllug] Excluding matches with grep

Wulf Forrester-Barker wulf.f-b at uhl.nhs.uk
Tue Jan 27 09:53:29 UTC 2004


Andrew <ah at gnd.com> suggested:

grep SuSE-FW /var/log/gateway.messages | grep -v martian | grep -v
SPT=53 >ft.txt 

Alternatively, you could shorten that using egrep, which allows you to
specify several matches at the same time:

grep SuSE-FW /var/log/gateway.messages | egrep -v 'martian|SPT=53' >
ft.txt 

The pipe acts as the delimiter. One thing that might be worth doing,
unless the log files are relatively trivial in size, is figuring out
which filter has the most effect. For example, say you start off with
100MB of logfiles. If the grep command returns 50MB of data and the
egrep command only returns 10MB of data (assuming that most lines *do*
have martian, SPT=53 or any other identifier you want to use in), I'd
run the egrep one first. That way the second command is working on a
much smaller dataset and thus the whole process will run a lot quicker.

I use a variety of command line tools to gather data for monthy reports
on our intranet and I discovered that the 20+ minutes required by my awk
script (that does the bulk of the work) could be reduced to about 4
minutes by using grep to filter out all the lines that the awk script
ignores.

Wulf


-- 
Wulf Forrester-Barker (Webmaster)
The Lewisham Hospital NHS Trust
http://www.lewisham.nhs.uk/


wulf.f-b at uhl.nhs.uk

**********************************************************************
DISCLAIMER:

Any opinions expressed in this email are those of the individual and
not necessarily the Trust. This email and any files transmitted with
it are confidential and intended solely for the use of the individual
or entity to whom they are addressed. Any unauthorised disclosure of
the information contained in this email is strictly prohibited.

The contents of this email may contain software viruses which could
damage your own computer system. Whilst we have taken every
reasonable precaution to minimise this risk, we cannot accept liability
for any damage which you sustain as a result of software viruses.
You should therefore carry out your own virus checks before opening
the attachment.

If you have received this email in error please notify the sender or
postmaster at uhl.nhs.uk. Please then delete this email.

University Hospital Lewisham
Tel: 020 8333 3000
Web: http://www.lewisham.nhs.uk/
**********************************************************************

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list