Effective grep of log file

前端 未结 4 1388
难免孤独
难免孤独 2021-01-22 19:41

I have a log file with a lot of lines on this format:

10.87.113.12 - - [2019-12-09T11:41:07.197Z] \"DELETE /page/sub1.php?id=alice HTTP/1.1\" 401 275 \"-\" \"ali         


        
4条回答
  •  天命终不由人
    2021-01-22 20:07

    You can achieve this by using just one grep and sed with this command,

    grep -E 'id=alice&jw_token=.* HTTP\/1.1" 200' main.log|sed -E 's/.*id=alice&jw_token=([a-zA-Z0-9]+).*/\1/'|uniq
    

    Here first part grep -E 'id=alice&jw_token=.* HTTP\/1.1" 200' main.log will filter out all lines not having alice and not having status 200 and next sed -E 's/.*id=alice&jw_token=([a-zA-Z0-9]+).*/\1/' part will just capture the token in group1 and replace whole line with just the token.

提交回复
热议问题