Bowie Bailey wrote:
> On 3/8/2012 5:19 AM, xTrade Assessory wrote:
>> Tom Kinghorn wrote:
>>> You can then grep through the spam files and search for a common
>>> string, eg score.
>>>
>>> e.g
>>> # cd /amavis/virusmails
>>> #
>>> # ls -la | grep "spam" | grep "Mar  8" | awk '{print $9}' | xargs
>>> zgrep -i "score="
>>>
>>>
>> wow 5 processes for each step ... that eventually gets your machine real
>> busy ...
>>
>> at least join all this greps into one grep -e pattern -e pattern or
>> egrep "pattern1|pattern2"
> That isn't the same search.
>
> grep -e pattern1 -e pattern2    = pattern1 or pattern2
>
> grep pattern1 | grep pattern2    = pattern1 and pattern2
>

yooo :) day starts good :)

the first ok, but depends, anyway my point was another, but let's look
deeper then

the second is not exactly an 'and' but a search within the results of
the first search
if you want a real 'and' you probable will write an regex as grep -e
"pattern1.*pattern2"

but that was not my point, simplicity was, writing cheaper expressions,
such one as above could render a machine or run for hours, well depends
on number of files and their size

grepping ls -la is a bad idea because you run one grep on *any* file, in
this case even on the . (dot)  entries, then another on each. so at
least use ls -l

but we could resume it in a better expression as

find /amavis/virusmails --maxdepth=2 -type f -name spam -mtime 1 -exec
zgrep -i "score=" {} \;

mtime 1 is yesterday, so you can run it from cron every day on the
yesterday results without need to check your script before each run,
depending on what you want you also may check mtime -1 or +1

this case you run two processes on each matching file without having
empty runs
supposed the files are really compressed, if not I wouldn't use zgrep here

if you prefer awk you could do it as

find /amavis/virusmails --maxdepth=2 -type f -name spam | awk '/Mar 8/
{print $9}' | zgrep -i "score="

what IMO is not very elegant and awk is expensive, anyway, it's 3 shots
on each file

Hans


-- 
XTrade Assessory
International Facilitator
BR - US - CA - DE - GB - RU - UK
+55 (11) 4249.2222
http://xtrade.matik.com.br

Reply via email to