Reputation: 170
i am facing challenge on to get the number of logs from a file from specific ip.
The logs look like:
Apr 24 16:00:28 192.168.5.5 : %ASA-6-106100: access-list inside denied udp inside/172.29.2.101(1039) -> outside/192.203.230.10(53) hit-cnt 1 first hit [0xd820e56a, 0x0]
Apr 24 16:00:28 192.168.5.6 : %ASA-6-106100: access-list inside denied udp inside/172.29.2.101(1039) -> outside/192.203.230.10(53) hit-cnt 1 first hit [0xd820e56a, 0x0]
i am using below command to get the count from ip 192.168.5.5 for "Apr 24"
# zcat filename | grep "Apr 24" | awk '{print $4}' | grep "192.168.5.5" | wc -l
I tried with the above command and i got the result but i am not sure the result is correct.
Please add your comments if i am doing anything wrong.
Upvotes: 0
Views: 232
Reputation: 130
awk is a good tool but this can be resolved using grep only. try the following.
zcat filename | grep "Apr 24" | grep "192.168.5.5 :" | wc -l
Upvotes: 2