Re: TOO SLOW: `echo ${LINE} | sed -n 's/^.* proto //p' | cut -f1 -d" "`

From: Juergen Heck (btd.heck_at_t-online.de)
Date: 07/15/03


Date: Tue, 15 Jul 2003 10:39:40 +0200


secheese wrote:
>
> I have a script that monitors a firewall drop log file and I need to
> pull the protocol fields. I used to know exactly where this field
> was, so I could easily get the field with this statement:
>
> PROTOCOL=`awk 'print $5'`
>
> But now the logs are dynamic and the field can be anywhere. One thing
> I do know is that the protocol field always follows a field labelled
> "proto". Thus the follow command gets it for me:
>
> PROTOCOL=`echo ${LINE} | sed -n 's/^.* proto //p' | cut -f1 -d" "`
>
> Trouble is, this command takes about 10 times as long to run as the
> awk did. The result is that the execution time for my script overall
> has gone from about 1 minute to 10 minutes.
>
> Can anyone think of a faster way to get the job done? BTW, perl is
> available, but I'm unfamiliar with the language.
>
> Thanks.

PROTOCOL=`awk '{sub(/.* proto /,"") ; print $1' yourlogfile`
for entry in $PROTOCOL
do
 ### process $entry
done

or

awk '{sub(/.* proto /,"") ; print $1' yourlogfile | while read entry
do
###process $entry
done

Regards
Juergen



Relevant Pages

  • Re: unix shell script ignores exit when in function that is piped to tee
    ... > I thought calling a function within a script did NOT create sub-shells. ... is going to be able to alter the log file to cover up any inappropriate ... entry in the log to the previous entry. ... The easiest way to use crypt to ...
    (comp.unix.shell)
  • Re: TOO SLOW: `echo ${LINE} | sed -n s/^.* proto //p | cut -f1 -d" "`
    ... > I have a script that monitors a firewall drop log file and I need to ... > pull the protocol fields. ... The result is that the execution time for my script overall ... BTW, perl is ...
    (comp.unix.shell)
  • TOO SLOW: `echo ${LINE} | sed -n s/^.* proto //p | cut -f1 -d" "`
    ... I have a script that monitors a firewall drop log file and I need to ... pull the protocol fields. ... The result is that the execution time for my script overall ...
    (comp.unix.shell)
  • Re: cron job with pid: xxxx Failed
    ... Do the script write a log or are there outputs sent to /dev/null. ... If the answer is /dev/null change the entry to redirect the output to a file ... > the cron yesterday & came across this entry in the cron log file under ... > There is no other explanation in the log file as to why it failed. ...
    (comp.unix.admin)
  • Re: cron job with pid: xxxx Failed
    ... Do the script write a log or are there outputs sent to /dev/null. ... If the answer is /dev/null change the entry to redirect the output to a file ... > the cron yesterday & came across this entry in the cron log file under ... > There is no other explanation in the log file as to why it failed. ...
    (comp.unix.aix)