我想使用AWK在Windows應用程序事件日誌中搜索字符串。以下是摘錄日誌:如何在AWK的搜索結果中打印缺少的字段?
W 05-Nov-14 10:09:36 261 CA_OSC <I>Process ax_be has finished without having received an explicit termination request from the component manager </I>
Time: 5.11.2014, 10:09:36, Line: 1161, File: \MCom\src\OSS\compmgr\src/CaCompPCB.cpp, Process: CaGenericMain (2448)
E 05-Nov-14 10:09:36 17 AY_ISC An error was detected in a process that is monitored by State Manager.
Time: 5.11.2014, 10:09:36, Process: C:\AXM\Service\bin\Rep.exe_1976,
Text: (05.11.2014 10:09:36) IVS SET: CMonitorThread::ProcessTermination(AppBE,5452) A critical process has
W 05-Nov-14 10:09:37 261 CA_OSC <I>Process main_ui has finished without having received an explicit termination request from the component manager </I>
Time: 5.11.2014, 10:09:37, Line: 1161, File: \MCom\src\OSS\compmgr\src/CaCompPCB.cpp, Process: CaGenericMain (2448)
我要搜索的字符串說,在事件日誌「ProcessTermination」,檢索輸出應該如下:
E 05-Nov-14 10:09:36 17 AY_ISC An error was detected in a process that is monitored by State Manager.
Time: 5.11.2014, 10:09:36, Process: C:\AXM\Service\bin\Rep.exe_1976,
Text: (05.11.2014 10:09:36) IVS SET: CMonitorThread::ProcessTermination(AppBE,5452) A critical process has
即。日誌和所有總結行發現匹配時。 搜索字符串可以在日誌行或任何摘要行中。 每行由新行字符分隔,並且此日誌文件是一個.txt文件。
到目前爲止,我已經嘗試下面的命令:
awk -v RS="\n(E|I|W)" "/ProcessTermination/" XA135420_2014_11_05_AppEventLog.txt
但結果,E | I | W缺失。即。在結果我(日誌行的第一個字段)|我有像
05-Nov-14 10:09:36 17 AY_ISC An error was detected in a process that is monitored by State Manager.
Time: 5.11.2014, 10:09:36, Process: C:\AXM\Service\bin\Rep.exe_1976,
Text: (05.11.2014 10:09:36) IVS SET: CMonitorThread::ProcessTermination(AppBE,5452) A critical process has
結果誰能幫我列出W |é?
注:我使用了GNU AWK 3.1.6在Windows 7
我測試你的代碼sccuess。 Cygwin awk 4.1.3 – bian
@ A-Ray:有什麼辦法可以通過GNU AWK實現這一點? – Smij01
@ Smij01 cygwin awk是GNU AWK。這不是你目前問題的原因,但得到一個新的gawk - 你的方式是過時的,你錯過了很多非常有用的功能和錯誤修復。 –