Effective grep of log file

前端 未结 4 1352
难免孤独
难免孤独 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:09

    If you're open to a perl oneliner:

    perl -ane '/id=alice&jw_token=([a-f0-9]+).+\b200\b/ && $h{$1}++;END{print"$_\n" for sort(keys %h)}' file.txt
    07e876afdc2245b53214fff0d4763730
    

    Explanation:

    /                           # regex delimiter
        id=alice&jw_token=      # literally
        ([a-f0-9]+)             # group 1, 1 or more hexa
        .+                      # 1 or more any character
        \b200\b                 # 200 surrounded with word boundaries
    /                           # regex delimiter, you may use /i for case insensitive
    

提交回复
热议问题