• awk


    前提

    AWK是一种处理文本文件的语言,是一个强大的文本分析工具。
    本文将使用命令awk将具有某个关键字的段落提取出来。

    准备数据

    "Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007fb2dc1aa800 nid=0x63f6 in Object.wait() [0x00007fb2be61f000]
       java.lang.Thread.State: WAITING (on object monitor)
    	at java.lang.Object.wait(Native Method)
    	- waiting on <0x00000000d6708ed8> (a java.lang.ref.ReferenceQueue$Lock)
    	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
    	- locked <0x00000000d6708ed8> (a java.lang.ref.ReferenceQueue$Lock)
    	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
    	at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
    
    "Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007fb2dc1a6000 nid=0x63f5 in Object.wait() [0x00007fb2be720000]
       java.lang.Thread.State: WAITING (on object monitor)
    	at java.lang.Object.wait(Native Method)
    	- waiting on <0x00000000d6706c00> (a java.lang.ref.Reference$Lock)
    	at java.lang.Object.wait(Object.java:502)
    	at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
    	- locked <0x00000000d6706c00> (a java.lang.ref.Reference$Lock)
    	at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
    
    "main" #1 prio=5 os_prio=0 tid=0x00007fb2dc04b800 nid=0x63ef waiting on condition [0x00007fb2e3382000]
       java.lang.Thread.State: TIMED_WAITING (sleeping)
    	at java.lang.Thread.sleep(Native Method)
    	at com.test.Test.main(Test.java:16)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    	at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
    

    段落提取

    假设我们需要的关键字为 nid=0x63ef

    keywords=0x63ef
    ## 以前后双换行符为一个段落
    ## 查询包含关键字nid=0x63ef的段落
    awk 'BEGIN {RS = "
    
    +";ORS = "
    
    "} /'${keywords}'/ {print $0}' test.log
    ## 查询不包含关键字nid=0x63ef的段落
    awk 'BEGIN {RS = "
    
    +";ORS = "
    
    "} !/'${keywords}'/ {print $0}' test.log
    
  • 相关阅读:
    monkeyrunner1
    也来复习一下数据库的一些知识1
    Monkey原理
    总结一下app客户端的测试点
    从侧计--mongkeyScript问题
    从侧计----monkeyScript实例----开启墨迹天气并添加城市,最后关闭app
    求助:关于sql如何统计时间的问题
    虚拟机无法分配内存 virtual memory exhausted: Cannot allocate memory
    Ubuntu14.04安装libusb
    E: 软件包 ffmpeg 没有可供安装的候选者
  • 原文地址:https://www.cnblogs.com/cjunn/p/12185394.html
Copyright © 2020-2023  润新知