VANHOR
V2EX  ›  问与答

关于日志统计过滤的问题

  •  
  •   VANHOR · Oct 18, 2019 · 1520 views
    This topic created in 2575 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
    lululau
    Oct 18, 2019
    1
    gawk -F'?' '{a[$1]++}END{for(k in a){print k": "a[k]}}'
    VANHOR
    VANHOR
    OP
    Oct 18, 2019
    2
    @lululau 好像不行... 日志中的其他内容也出来了
    lululau
    lululau
    Oct 18, 2019
    3
    @VANHOR 发个样本
    pkookp8
    pkookp8
    Oct 18, 2019 via Android
    4
    awk -F"?" 'BEGIN{abc=0}{if(index{$0, "abc/def") != 0){abc++}}END{printf("%d times abc\n", abc)}'
    pkookp8
    pkookp8
    Oct 18, 2019 via Android
    5
    @pkookp8 $0 改成$1
    手写的,不知道还有没有其他错😂
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1271 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 21:04 · PVG 05:04 · LAX 13:04 · JFK 16:04
    ♥ Do have faith in what you're doing.