I am having issue to use grep with regular expression I am trying to read and filter some logs on server
kubectl logs -lname=ambassador --tail=40 | grep ACCESS | grep '" 200 ' | grep ' /api/entitlements '
so this returns some logs and it is fine but I need to search for all api including entitlements in their path. I tried this:
kubectl logs -lname=ambassador --tail=40 | grep ACCESS | grep '" 200 ' | grep ' *entitlements* '
but nothing returns
can anyone help?
You may use awk
to avoid multiple grep
command and do all filters in one command:
kubectl logs -lname=ambassador --tail=40 | awk '/ACCESS/ && /" 200 / && /entitlements/'
/substr/
searches for regex pattern substr
in each line of awk
. &&
ensures that all the given patterns are found in same line.
Would you try the following:
kubectl logs -lname=ambassador --tail=40 | grep -E 'ACCESS.*entitlements.*" 200 '
The grep
searches for the line which contains substrings ACCESS
, entitlements
, and " 200
in this order.
You can try below command to grep multiple keywords -
kubectl logs -lname=ambassador --tail=40 |grep "entitlements\|ACCESS\| 200"