Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk grouping report 1

Status
Not open for further replies.

stfaprc

Programmer
Feb 10, 2005
216
US
I have an awk line of:
awk '{if ($6 == "allow") print $1,$2,$3,$13,$15,$14,$6,$17,$18,$19,$20,$21}' firebox

$3=protocol, $17=ip address target
I would like to be able to get awk produce a report that would group on field #3, giving me a count of how many times it appeared in firebox for each ip address.
For instance:
smtp 10.10.10.10 5 times
smtp 10.10.10.30 9 times
ssh 10.10.10.50 1 times

Is this do-able with awk?
 
Code:
{ arr[$3 OFS $17]++ }
END {
  for (i in arr)
    printf("%s %d times\n", i, arr[i])
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hello Vlad,
where do i put the code you sent?
does it need to in a file and awk run with the -F option ?

thanks.
 
Code:
nawk [red]-f[/red] myAWKscript.awk firebox

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top