Parsing Different Date Format From File Name

(Goutam Das) #1

Hi all,

I have a requirement where there are no date getting captured in the logs, whereas time has been captured. But the log file name has date + time in it. And there are different types of file name.

For ex. I have a file one type: XXXX_ZZZZZZZZ_TTTTTT_11062018151447664.log

If you look at the number string:
First 2 digit is Day
3rd and 4th digit is month
5th, 6th, 7th and 8th digit is year
and, subsequently hh:mm:ss:SSS

2nd type of file: XXXXXX.ZZZZ.2018.

If you look at the number string:
First 4 digit is Year
Next 2 digit is month
Next 2 digit is day

Now, what I want to do is, I want to parse both of the file name format in the grok script and extract as YYYY-MM-dd HH:mm:ss.SSS for the 1st file type, and,
YYYY-MM-dd HH:mm:ss for the 2nd file type...

can any one help please?