1

这是困扰我的:

我有一个日志文件,以特定格式编写,例如:

[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 的终端屏幕上通过尾巴查看此日志,它看起来很糟糕(不,我无法更改屏幕,它是嵌入式设备)。

你能帮我创建一个tail/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

从上面的长线?

谢谢

4

2 回答 2

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
于 2012-06-12T10:04:02.417 回答
1

我建议sed彻底清除格式:

tailf -f logfile | sed -e 's/\[MSG:\([^]]*\)\]/\1/' -e 's/\[[^]]*\] *//g'
于 2012-06-12T09:55:51.113 回答