Jubi Jubi - 27 days ago 5
Bash Question

awk print line based on condition of a column

I have application logs and I need to print all lines with execution times exceeding 10000 ms. In the sample below only first line is printed since line 2 doesnt exceed 10k ms and line 3 doesn't show any execution time.

SERVICE_NAME: | API: GetContents | 20160927000511741 | EXECUTION TIME: 10130(ms)
SERVICE_NAME: | API: GetContentsExtend | 20160927000511741 | EXECUTION TIME: 22(ms)
SERVICE_NAME: | API: GetContentsExtended | 20160927000511741 | Current TN: -15698724705531331

I could do this by doing multiple steps

store execution value in a file:

cat logfile.log | grep "EXECUTION TIME:" | awk '{print $NF}' | cut -d "(" -f1 | awk '{if ($1>9999) print $1}' >> input.txt

loop through this input file traversing the same log

cat input.txt | while read line
cat logfile.log | grep $line"(ms)" >> output.txt

Can this be done maybe by a 1-liner command? Whats giving me a hard time is the execution time value has (ms) after it.


If the execution time is >= 10000, then there will be at least 5 digits before the string "(ms)", so:

grep -E 'EXECUTION TIME: [[:digit:]]{5,}\(ms\)' filename