前提
AWK是一種處理文本文件的語言,是一個(gè)強(qiáng)大的文本分析工具。
本文將使用命令awk將具有某個(gè)關(guān)鍵字的段落提取出來。
準(zhǔn)備數(shù)據(jù)
"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)
段落提取
假設(shè)我們需要的關(guān)鍵字為 nid=0x63ef
keywords=0x63ef
## 以前后雙換行符為一個(gè)段落
## 查詢包含關(guān)鍵字nid=0x63ef的段落
awk 'BEGIN {RS = "\n\n+";ORS = "\n\n"} /'$awk,關(guān)鍵字段落,awk,提取關(guān)鍵字'/ {print $0}' test.log
## 查詢不包含關(guān)鍵字nid=0x63ef的段落
awk 'BEGIN {RS = "\n\n+";ORS = "\n\n"} !/'$awk,關(guān)鍵字段落,awk,提取關(guān)鍵字'/ {print $0}' test.log
總結(jié)
以上所述是小編給大家介紹的Linux 中awk 提取包含某個(gè)關(guān)鍵字的段落,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
您可能感興趣的文章:- Linux awk將文件某列按照逗號(hào)分隔的例子
- 一天一個(gè)shell命令 linux文本內(nèi)容操作系列-awk命令詳解
- linux awk時(shí)間計(jì)算腳本及awk命令詳解
- linux之a(chǎn)wk命令的用法
- Linux里awk中split函數(shù)的用法小結(jié)