Support Questions

Find answers, ask questions, and share your expertise

Apache NiFi Extract multiple dates and change format

avatar
New Contributor

I have a file that can contain a variable number of dates in the format ddHHmm:ssMMMYY and I want to change them to yyy/MM/dd HH:mm:ss.

 

I currently have an ExtractText processor with property field date with a value of (\d{6}:\d{2}[a-zA-Z]{3}\d{2}) and I have Enable repeating capture group set to true.

 

This is then sent to a ReplaceText processor that searches the same regex (\d{6}:\d{2}[a-zA-Z]{3}\d{2}) and replaces it with ${date:toDate("ddHHmm:ssMMMyy"):format("yyyy/MM/dd HH:mm:ss")}

 

My problem is that it that the ReplaceText processor will replace every match with only the first result from the ExtractText processor instead of its respective date-time. This results in all the dates and times in the file being exactly the same.

1 REPLY 1

avatar
Super Guru

@redmonc2   You should update the post with the input data, and a screen shot of your flow, for better responses from your peers.  If you provide this info I will update my response below.

 

Without being able to see the input data I believe you just need to adjust your flow so that you are breaking up the input data into multiple flowfiles.   For example, if that input data is lines of dates you want to change formats, your flow should split the lines with SplitText, then get each split FlowFiles date to an attribute called date (${date}) with ExtractText that uses regex to get the entire split content to the date attribute.  With an attribute called date in each flowfile,  you can then use your expression language in updateAttribute:

 

${date:toDate("ddHHmm:ssMMMyy"):format("yyyy/MM/dd HH:mm:ss")}

 

Once you have the format correct for each date, you can proceed with the dates downstream as attributes or write them back to the content of the flowfile and merge them together.

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  

 

Thanks,


Steven @ DFHZ