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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting array to a certain word

Status
Not open for further replies.

felix001

Technical User
Nov 15, 2008
102
GB
I am trying to add an array which is a word within a certain postion in my log file...

cat /var/log/messages | grep "read failure" | awk '{ip[$14]++}END{for(j in ip) print j,"ip[j]"}'

This works and shows me how many hits in my logs file i have had for the IP address ($14), but ideally instead of entering $14, i what to tell it, "its the word after client and space with that line"

Any help would be great ...

Fir3net.com
 
Anyway, a simpler way:
awk '/read failure/{++ip[$14]}END{for(j in ip)print j,ip[j]}' /var/log/messages

its the word after client and space with that line
the literal word "client" ?
awk '/read failure/{for(i=1;i<NF;++i)if($i=="client"){++ip[$(i+1)];next}}END{for(j in ip)print j,ip[j]}' /var/log/messages

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thats great, thanks for the quick repsonse.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top