Issue
need to check logs, logs format as below, normally I get logs by cat ***.log | grep --color -a 'keywords'
I wanna get all logs which proctm
> 30000µs, anyone knows how to write linux command? thank u
traceid=1f8a1b84c113b31e2fd6589cbf339600|***|errcode=0|proctm=28887µs|usetrx= false|ormstats=0 0 0|
Solution
With your shown samples, could you please try following. We could do this in a single awk
itself.
awk '
/keyword/ && match($0,/proctm=[^µ]*/){
val=substr($0,RSTART,RLENGTH)
sub(/[^0-9]+/,"",val)
if(val+0>30000){ print }
}
' Input_file
Explanation: Adding detailed explanation for above.
awk ' ##Starting awk program from here.
/keyword/ && match($0,/proctm=[^µ]*/){ ##Using match function to match regex proctm= till µ here.
val=substr($0,RSTART,RLENGTH) ##Creating val which has sub string which has matched regex value.
sub(/[^0-9]+/,"",val) ##Substituting everything apart from digit in val.
if(val+0>30000){ print } ##Checking if val is greater than 30000 then print current line.
}
' Input_file ##Mention *.log to pass all log files here.
Answered By - RavinderSingh13 Answer Checked By - Marilyn (WPSolving Volunteer)