VANHOR
V2EX  ›  问与答

关于日志统计过滤的问题

  •  
  •   VANHOR · Oct 18, 2019 · 1258 views
    This topic created in 2410 days ago, the information mentioned may be changed or developed.
    现在有一个 3 个多 G 的日志文件在 linux 中,现在想统计某个字段出现的次数

    大概格式是这样的

    uri[/abc/def/ghi?giftno=1004&no=core&transid=483]

    想统计的是问号?之前的内容出现过多少次,最后想得到这样一个结果

    100 次 /abc/def/ghi
    50 次 /photo/ab/cd
    10 次 /aaa/bbb

    谢谢..我知道很简单,但是真的不会
    5 replies    2019-10-18 14:28:07 +08:00
    lululau
        1
    lululau  
       Oct 18, 2019
    gawk -F'?' '{a[$1]++}END{for(k in a){print k": "a[k]}}'
    VANHOR
        2
    VANHOR  
    OP
       Oct 18, 2019
    @lululau 好像不行... 日志中的其他内容也出来了
    lululau
        3
    lululau  
       Oct 18, 2019
    @VANHOR 发个样本
    pkookp8
        4
    pkookp8  
       Oct 18, 2019 via Android
    awk -F"?" 'BEGIN{abc=0}{if(index{$0, "abc/def") != 0){abc++}}END{printf("%d times abc\n", abc)}'
    pkookp8
        5
    pkookp8  
       Oct 18, 2019 via Android
    @pkookp8 $0 改成$1
    手写的,不知道还有没有其他错😂
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2156 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 16:12 · PVG 00:12 · LAX 09:12 · JFK 12:12
    ♥ Do have faith in what you're doing.