1

I have a log file where data entries are as follows Each entry starts with time:

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 

Now I want to print as single line, only the entries between the time:. For eg, after time :, I want to print all records as single line, so in my case, it should print like

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 

I have tried with below commend, It's displaying on screen but when try to redirect/append it's not working.

tailf /var/log/dirsrv/slapd-ldap/audit | awk '/^time:/ {if (NR!=1)print"";printf $0}{printf $0}END{print"";}' | logger 

Is there any command for doing this?

3
  • It seems the formatting of your question is wrong. This makes it hard to read. Please try to fix it. Commented Jun 9, 2017 at 15:54
  • The whole point is using > instead of |. because you want to put text into a file instead of passing it to a command. you should make clear what logger is. Commented Aug 7, 2017 at 16:12
  • logger is the command, which forward the logs to messages log file Commented Aug 10, 2017 at 13:38

1 Answer 1

1

Maybe you can try something like this:

awk '/^time:/ { print "\n" } { printf "%s ",$0 }' /var/log/dirsrv/slapd-ldap/audit > logger 
2
  • 1
    Nice solution, but it appears the OP wants to tail from the audit file and skip the first newline so I'd write tailf /var/log/dirsrv/slapd-ldap/audit | awk 'NR>1 && /^time:/ { print "\n" } { printf "%s ",$0 }' > logger. Commented Aug 7, 2017 at 16:13
  • Thank you for your response. It's I have tried already. It will display on screen only, it won't redirect to file. Issue also same. Commented Aug 10, 2017 at 13:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.