我有一个日志文件,其中的数据条目如下,每个条目都以时间开头:
time: 20170509123420
dn: uid=abc,ou=People,dc=test,dc=example,dc=com
changetype: modify
replace: passwordAllowChangeTime
replace: passwordExpirationTime
replace: passwordRetryCount
replace: pwdpolicysubentry
replace: modifiersname
modifiersname: uid=admin,ou=administrators,ou=topologymanagement,o=netscaperoot
replace: modifytimestamp
modifytimestamp: 20170509113420Z
time: 20170509123621
dn: cn=nsPwPolicyContainer,dc=test,dc=example,dc=com
changetype: add
objectClass: nsContainer
objectClass: top
cn: nsPwPolicyContainer
creatorsName: uid=admin,ou=administrators,ou=topologymanagement,o=netscaperoot
modifiersName: uid=admin,ou=administrators,ou=topologymanagement,o=netscaperoo
现在我想打印成一行,只打印时间:之间的条目。例如,在时间:之后,我想将所有记录打印成一行,所以在我的情况下,它应该打印成
time: 20170509123420 dn: uid=abc,ou=People,dc=test,dc=example,dc=com changetype: modify replace: passwordAllowChangeTime - replace: passwordExpirationTime - replace: passwordRetryCount - replace: pwdpolicysubentry - replace: modifiersname modifiersname: uid=admin,ou=administrators,ou=topologymanagement,o=netscaperoo t - replace: modifytimestamp modifytimestamp: 20170509113420Z
我已尝试以下建议,它显示在屏幕上,但当尝试重定向/附加时它不起作用。
tailf /var/log/dirsrv/slapd-ldap/audit | awk '/^time:/ {if (NR!=1)print"";printf $0}{printf $0}END{print"";}' | logger
有什么命令可以做到这一点吗?
答案1
也许你可以尝试这样的事情:
awk '/^time:/ { print "\n" } { printf "%s ",$0 }' /var/log/dirsrv/slapd-ldap/audit > logger