linux - Grepping and grouping for errors in log files -
i'm on linux (and on aix) , have bunch of log files in folder. have grep command filter out of errors in format follows.
createorder_hostname_tee.log:2015-09-29 15:42:06,715:error :thread-26_createorder: [1443555726715] error1 [system]: class1 createorder_hostname_tee.log:2015-09-29 15:42:06,715:error :thread-15_createorder: [1443555726715] error1 [system]: class1 createorder_hostname_tee.log:2015-09-29 15:42:06,715:error :thread-28_createorder: [1443555726715] error2 [system]: class2 scheduleorder_hostname_tee.log:2015-09-30 03:55:05,011:error :thread-5_scheduleorder: [1443599705009] error3 [system]: class3
is possible using combination of grep/awk/sed above data in format this?
api: error: count createorder: error1: 50 createorder: error2: 50 scheduleorder: error3: 50
if not, possible format this? use wc or similar count distinct errors.
api: date: error createorder: 2015-09-29 15:42:06,715: error1 createorder: 2015-09-29 15:42:06,715: error2 scheduleorder: 2015-09-29 15:42:06,715: error3
edit 1:
the error string (including spaces). basically, in between brackets below should displayed.
[1443555726715] error1: error description. [system]: class1
input=$(your grep command) formatted=$( echo "$input" | sed 's/^\([^_]*\).*[0-9]*\] \([^[]*[^\[ ]\).*/\1: \2/' ) kinds=$(echo "$formatted" | sort -u) while ifs= read kind count=$(echo "$formatted" | grep "$kind" | wc -l) echo "$kind: $count" done <<< "$kinds"
for input given in question, gives output:
createorder: error1: 2 createorder: error2: 1 scheduleorder: error3: 1
everything done in memory, might not feasible large data structures (dozens or hundreds of megabytes). in these cases can use temporary files instead of shell variables (e. g. echo "$input" | sed … > formatted.tmp
, sort -u formatted.tmp > kinds.tmp
etc.).
Comments
Post a Comment