Reputation: 973
Have the following lines in logs
queryparam={createdTime=1524456000000,limit=1000, sort=name}
queryparam={createdTime=1524457000000, sort=name,limit=1001}
queryparam={createdTime=1524457000000, sort=name, name=alpha, limit=1001}
queryparam={createdTime=1524458000000, sort=name}
Is there a bash script to fetch only rows which have limit greater than 1000?
P.S. Not sure how to parse the field to get limit value and check whether it is greater than 1000.
Upvotes: 1
Views: 43
Reputation: 133458
EDIT: Since OP mentioned field is NOT always same so adding this solution now.
awk 'match($0,/limit=[0-9]+/){split(substr($0,RSTART,RLENGTH),array,"=");if(array[2]>1000){print}}' Input_file
Following awk
may help you here.
awk -F"[=,]" '/limit/ && $5>1000' Input_file
It will only look for those lines which have string limit
and their value is greater than 1000
too and print them then.
Explanation:
awk -F"[=,]" ' ##Setting field separator as = and , here for all the lines of Input_file.
/limit/ && $5>1000 ##Checking here if a line contains string line in it and checking if its 5th column is grater than 1000, since awk works on concept of condition then action so here mentioning the condition and NOT mentioning the action. So by default print action of current line will happen.
' Input_file ##Mentioning Input_file name here.
Upvotes: 1