I'd like to pipe the output of an ldapsearch to sanitize the dates returned - I presume sed and/or awk can help with this but would appreciate a bit of help.

The fixed length date format in the LDIF output file is like this:

whenCreated: 20111209103130.0Z

Any pointers to get it in this format would be great:

whenCreated: DD-MM-YY hh:mm 

eg (using above example):

whenCreated: 09-12-2011 10:31

Does this little piece of sed help you?

sed -e 's/whenCreated: \([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\).*/whenCreated: \3-\2-\1 \4:\5/g'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.