awk parsing log fields

From thelinuxwiki
Jump to: navigation, search

lets say you need the field after something denoted by a precurser.

precurser = rule:

example...

# echo "1 2 3 4 5 6 rule: 7 8 9 10" | awk '{for (i=1; i<=NF; i++) if ($i=="rule:") print $(i+1)}'
7