我有点儿是整个Linux的新手,但我有一个doozie的时间试图找出如何筛选我的qmail日志文件。
在这一点上,我想要做的是做一个search,输出qmail-local-handlers后方括号内的内容。 所以,例如,我的日志片段中的第一行…
(Oct 3 10:17:21 125388-web2 qmail-local-handlers [18145]:[email protected])
…我想要它输出18145。
我不知道我可以运行什么命令来获得我正在寻找的结果。 谁能帮忙?
这里是我使用的一些示例数据,如果它会帮助。 非常感谢!!
Oct 3 10:17:21 125388-web2 qmail-local-handlers [18145]:[email protected] | Oct 3 10:29:14 125388-web2 qmail-local-handlers [22908]:[email protected] | Oct 3 10:29:30 125388-web2 qmail-local-handlers [23017]:[email protected] | Oct 3 10:30:58 125388-web2 qmail-local-handlers [23815]:[email protected] | Oct 3 10:31:04 125388-web2 qmail-local-handlers [23861]:[email protected] | Oct 3 12:06:52 125388-web2 qmail-local-handlers [30174]:[email protected] | Oct 3 12:07:03 125388-web2 qmail-local-handlers [30240]:[email protected] | Oct 3 12:19:05 125388-web2 qmail-local-handlers [3243]:[email protected] |
这将抓住(第一)对方括号之间的数字:
sed "s/.*\[\([0-9]\+\)\].*/\1/" logfile
你有没有尝试过:
cut -d '[' -f 2 LOGFILE | cut -d ']' -f 1