码迷,mamicode.com
首页 > 其他好文 > 详细

awk - 提取包含某个关键字的段落

时间:2020-01-13 00:49:16      阅读:371      评论:0      收藏:0      [点我收藏+]

标签:关键字   moni   nat   handler   strong   and   key   nal   tin   

前提

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 = "\n\n+";ORS = "\n\n"} /'${keywords}'/ {print $0}' test.log
## 查询不包含关键字nid=0x63ef的段落
awk 'BEGIN {RS = "\n\n+";ORS = "\n\n"} !/'${keywords}'/ {print $0}' test.log

awk - 提取包含某个关键字的段落

标签:关键字   moni   nat   handler   strong   and   key   nal   tin   

原文地址:https://www.cnblogs.com/cjunn/p/12185394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!