simbabarry simbabarry - 4 months ago 12
Linux Question

extract log time from log file

How do I extract the time part only from a string like this.

[20/06/2016 15:55:42.079] <Messenger> Echo test request


I just want to get this part 15:55:42.079 from the log.

sat sat
Answer

You can try this:

awk -F']| ' '{print $2}' <<< "STRING"

Test:

$ awk -F']| ' '{print $2}' <<< "[20/06/2016 15:55:42.079] Echo test request"
15:55:42.079