#!/usr/bin/awk -f #################################################################### # LogDissector - a format-independent logfile analysis tool. # # Author: Paul Reiber - paul at reiber dot org # URL: http://reiber.org/Code/logDissector #################################################################### # PLATFORMS: # should work on most Linux implementations - mawk compatible # # USAGE EXAMPLES: # awk -v skip="1,3,5" -v collect="2,4,6" -f logdissector.awk any.logfile # tail -1000000 /var/log/messages | awk -f logdissector.awk # awk -v ext=_syslog_`date +%j` -f logdissector.awk /var/log/syslog # # if you encounter problems it may be related to how your awk understands FS # BEGIN { FS="\t\]\[| " } # fields are separated by space tab pipe open-bracket or close-bracket BEGIN { print "FS=[" FS "]" } # fields are separated by space tab pipe open-bracket or close-bracket # for every input line... { line=""; for( word=1; word<=NF; word=word+1){ # initialize line and loop over all fields setting "word" to the field number #print "in[" word "]=" $(word) if ("," $(word) "," !~ /^,,$/) { words[$(word)]++; } # all non-null word gets counted if (index("," skip "," , "," word ",")>0) { line=line " " } # honor skip on commandline else if (index("," collect "," , "," word ",")>0) { line=line " "; collection[$(word)]++ } # honor collect too else if ("," $(word) "," ~ /^,,$/) { line=line " " } # empty fields (happens because of our FS) else if ($(word) ~ /^[0-9]?[0-9]:[0-9][0-9](:[0-9][0-9])?$/) { line=line "