2012-06-12 41 views
1

這是困擾我:尾礦的awked日誌

我有一個日誌文件,寫在一個特定的格式,如:

[DEBUG 7] 2012-06-12 09:26:37.847 [MOD: UNK/0 ] [FILE:ModuleManager.cpp:541] [FUNC: ModuleManager::handleStatusRequestMessage] [MSG:Got request for unsupported ALLOCATION_STATUS ] 

所以塊很好分離。我通過一個80x25終端屏幕上的尾部查看此日誌,看起來很糟糕(不,我無法更改屏幕,它是嵌入式設備)。

你能幫我創造一個尾/ AWK(或類似)的組合來實現這樣的:從長

2012-06-12 09:26:37.847 Got request for unsupported ALLOCATION_STATUS 

2012-06-12 09:26:37.847 ModuleManager::handleStatusRequestMessage - Got request for unsupported ALLOCATION_STATUS 

2012-06-12 09:26:37.847 ModuleManager.cpp:541 ModuleManager::handleStatusRequestMessage - Got request for unsupported ALLOCATION_STATUS 

上面的線?

感謝

+0

不要改變你的屏幕。反而成爲80欄文本的倡導者!輸出,日誌,源代碼 - 全部在80列以下。告訴你的朋友;它不僅僅是70年代的遺物。這對未來和過去都是一個好主意! –

+0

@WilliamPursell:兩個字:「大顯示器」。 –

+0

@Dennis大型監視器,我可以並排顯示6-8個文件 - 除非其中一個每行使用120列! –

回答

2
$ awk -F '[][]' '{print $3, $10}' logfile 
2012-06-12 09:26:37.847 MSG:Got request for unsupported ALLOCATION_STATUS 
$ awk -F '[][]' '{print $3, $8, $10}' logfile 
2012-06-12 09:26:37.847 FUNC: ModuleManager::handleStatusRequestMessage MSG:Got request for unsupported ALLOCATION_STATUS 
$ awk -F '[][]' '{print $3, $6, $8, $10}' logfile 
2012-06-12 09:26:37.847 FILE:ModuleManager.cpp:541 FUNC: ModuleManager::handleStatusRequestMessage MSG:Got request for unsupported ALLOCATION_STATUS 

$ awk -F '[][]|MOD:|FUNC:|FILE:|MSG:' '{print $3, $8, $11 " - " $14}' inputfile 
2012-06-12 09:26:37.847 ModuleManager.cpp:541 ModuleManager::handleStatusRequestMessage - Got request for unsupported ALLOCATION_STATUS 
+0

結合尾巴它是完美的:'tail -f log.txt | awk -F'[] []''{print $ 3,$ 10}'' – fritzone

1

我建議sed進行大刀闊斧的格式消滅:

tailf -f logfile | sed -e 's/\[MSG:\([^]]*\)\]/\1/' -e 's/\[[^]]*\] *//g'