【发布时间】:2015-05-14 16:54:39
【问题描述】:
我正在尝试编写一个脚本,该脚本将根据列/分隔符找到唯一的行(第一次出现)。在这种情况下,据我了解,分隔符是“:”。
例如:
May 14 00:00:01 SERVER1 ntp[1006]: ntpd[Info]: 1430748797.780852: ndtpq.c(20544): this is the log
May 14 00:00:01 SERVER1 ntp[1006]: ntpd[Info]: 1430748797.780853: ndtpq.c(20544): this is another log
May 14 00:00:02 SERVER1 ntp[1006]: ntpd[Info]: 1430748798.780852: ndtpq.c(20544): this is another log
May 14 00:00:03 SERVER1 ntp[1006]: ntpd[Info]: 1430748799.780852: ndtpq.c(20544): this is the log
May 14 00:00:04 SERVER1 ntp[1006]: ntpd[Info]: 1430748800.780852: ndtpq.c(20544): this is the log
May 14 00:00:04 SERVER1 ntp[1006]: ntpd[Info]: 1430748800.790852: ndtpq.c(20544): this is the log
May 14 00:00:05 SERVER1 ntp[1006]: ntpd[Info]: 1430748801.790852: ndtpq.c(20544): thisis really different log
想要的输出:
May 14 00:00:01 SERVER1 ntp[1006]: ntpd[Info]: 1430748797.780852: ndtpq.c(20544): this is the log
May 14 00:00:01 SERVER1 ntp[1006]: ntpd[Info]: 1430748797.780853: ndtpq.c(20544): this is another log
May 14 00:00:05 SERVER1 ntp[1006]: ntpd[Info]: 1430748801.790852: ndtpq.c(20544): thisis really different log
我可以使用以下命令找到 uniq 日志,但是使用这种方式会丢失时间戳。
cat fileName |awk -F: '{print $7}'
【问题讨论】:
-
确定应该分组的条目的标准是什么?是消息的内容吗?如果是这样,如果稍后生成相同的消息怎么办?
-
是消息的内容,以后看到可以忽略。只需要第一次出现。