Optimize grep, awk and sed shell stuff
Posted
by kockiren
on Stack Overflow
See other posts from Stack Overflow
or by kockiren
Published on 2010-06-01T11:42:33Z
Indexed on
2010/06/01
12:13 UTC
Read the original article
Hit count: 355
I try to sum the traffic of diffrent ports in the logfiles from "IPCop" so i write and command for my shell, but i think its possible to optimize the command.
First a Line from my Logfile:
01/00:03:16 kernel INPUT IN=eth1 OUT= MAC=xxx SRC=xxx DST=xxx LEN=40 TOS=0x00 PREC=0x00 TTL=98 ID=256 PROTO=TCP SPT=47438 DPT=1433 WINDOW=16384 RES=0x00 SYN URGP=0
Now i grep with following Command the sum of all lengths who contains port 1433
grep 1433 log.dat|awk '{for(i=1;i<=10;i++)if($i ~ /LEN/)print $i};'|sed 's/LEN=//g;'|awk '{sum+=$1}END{print sum}'
The for loop i need because the LEN-col is not on same position at all time.
Any suggestion for optimizing this command?
Regards Rene
© Stack Overflow or respective owner