我遇到了很多使用情况,从一个(通常是换行符分隔的)stream中获取input,并以顶级的方式汇总它(参见top,iotop等)将会非常有用。 一种即时的数据透视表。
例如采取log-esqueinput:
I heard A from unit 1 and it said "Great!" 56 I heard A from unit 2 and it said "Oh no!" 42 I heard C from unit 1 and it said "Waiting for input." 33 I heard B from unit 3 and it said "Stopped." -1 ...
从这里,我们可以运行一个正则expression式和组指标的工具:
topify [lineout] [regex] [name #1] [group #1] [name #2] [group #2] [All other columns name position] where: lineout is the number of lines before removing it from the display regex is a regex of the lines to match, complete with group indicators name #n is a string for the title of column n group #n is the number of the group in the regex
例如
topify '/^I heard ([AZ]) from unit ([1-9]) and it said "(.*)" ([-0-9]*)$/' Unit 2 Status 1 Message 3 RetVal 4
这将以交互方式显示,使得列可以被select/重新sorting等。
Unit Status Message Retval 1 C Waiting for input. 33 2 A Oh no! 42 3 B Stopped. -1
我了解它的脆弱性,但是如果它之前没有build成,并且在我开始构build它之前想要检查,我会感到非常惊讶。 我也很感谢,这不是特别复杂写,所以也许每个人都刚刚实施自己的解决scheme…
有没有人看过这样的工具?
(请原谅我在这里使用的标签,我知道我可能会推动/打破一些标签的规则,但这是非常普遍的,欢迎提出build议。)
你不需要编写一个工具,标准的Unix工具集可以适应你就好了。
#!/bin/bash echo -e 'Unit\tStatus\tMessage\t\t\tRetval' cat /var/log/filename | awk '{match($0,"\".*\"",a)}{print $6 "\t" $3 "\t" a[0] "\t\t" $NF}' |sort -k<fieldnum>
把它放在一个.sh文件中,然后运行它。