Hi guys,
i am trying to analyze a text file using awk and am not able to solve this issue.
This is the piece of code that I have written
BEGIN {
## Time to count MACs -> 5 seconds.
TIME_LIMIT = 5;
k = 50000;
}
## For every line.
{
time_in_seconds = $1
mac = $2;
if ( mac_pair[mac] ) {
diff = time_in_seconds - mac_pair[mac];
##print diff
if ( diff > TIME_LIMIT ) {
++counter;
printf "%s\n", "Incrementing counter: " $0;
}
} else {
## Increment counter for first time of this MACs.
++counter;
printf "%s\n", "Incrementing counter: " $0;
}
mac_pair[mac] = time_in_seconds;
## NEW ROUTINE
if ( NR = k){
remove_time = time_in_seconds-5;
##print remove_time
for (x in mac_pair)
{ if (mac_pair[x] < remove_time )
{ delete mac_pair[x]
print x}
}
k = k + 50000;
}
}
END {
printf "%s = %d\n", "Counter is:", counter;
}
The code goes through lines, matches and increments a counter if there is no match for the previous 5 seconds. The issue I m facing is i have to run this over huge files and my ram gets exhausted. That is why I have included a new routine which will discard packets after a set number of lines have been processed.
If i try to print NR before and after it runs this routine, i see it gets altered. Also the routine within if ( NR = k) runs for every line. I am not sure why.
here are some sample input
1319170474.165379 164:186:219:250:181:93:255:255:255:255:255:255:130.192.9.212:130.192.9.255:55549:1947
1319170474.308849 0:13:41:11:173:255:1:0:94:0:0:13:192.168.100.129:224.0.0.13:8192:33198
1319170474.543025 0:224:129:88:169:186:255:255:255:255:255:255:192.168.10.126:192.168.10.255:631:631
1319170474.546619 0:25:209:27:17:125:255:255:255:255:255:255:130.192.9.131:255.255.255.255:631:631
1319170474.165379 164:186:219:250:181:93:255:255:255:255:255:255:130.192.9.212:130.192.9.255:55549:1947
1319170474.308849 0:13:41:11:173:255:1:0:94:0:0:13:192.168.100.129:224.0.0.13:8192:33198
1319170474.543025 0:224:129:88:169:186:255:255:255:255:255:255:192.168.10.126:192.168.10.255:631:631
1319170474.546619 0:25:209:27:17:125:255:255:255:255:255:255:130.192.9.131:255.255.255.255:631:631
help me out