Linux中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 f.ReferenceQueue$Lock)
at ve(ReferenceQueue.java:144)
- locked <0x00000000d6708ed8> (a f.ReferenceQueue$Lock)
at ve(ReferenceQueue.java:165)
at f.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 f.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at HandlePending(Reference.java:191)
- locked <0x00000000d6706c00> (a f.Reference$Lock)
at f.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)
st.Test.main(Test.java:16)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at flect.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"} /'$awk,关键字段落,awk,提取关键字'/ {print $0}' test.log
## 查询不包含关键字nid=0x63ef的段落
awk 'BEGIN {RS = "\n\n+";ORS = "\n\n"} !/'$awk,关键字段落,awk,提取关键字'/ {print $0}' test.log
linux换行按哪个键总结
以上所述是⼩编给⼤家介绍的Linux 中awk 提取包含某个关键字的段落,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!
如果你觉得本⽂对你有帮助,欢迎转载,烦请注明出处,谢谢!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论