Support Questions
Find answers, ask questions, and share your expertise

How do I parse/split a line based on fixed length using regex in Nifi? ,How to substring a line based on length a line in Nifi using regex?

How do I parse/split a line based on fixed length using regex in Nifi? ,How to substring a line based on length a line in Nifi using regex?

New Contributor

My data looks like as below

Mar 29 2004 09:55:03: %PIX-6-302006: Teardown UDP connection for faddr 194.224.52.6/3645b4

Mar 29 2004 09:55:03: %PIX-6-302006: Teardown UDP connection for faddr 194.224.52.4/4454889

Mar 29 2004 09:55:03: %PIX-6-302006: Teardown UDP connection for faddr 80.58.34.99/32772666677

Mar 29 2004 09:55:03: %PIX-6-302006: Teardown UDP connection for faddr 80.132.253.64/147899999999456456

Mar 29 2004 09:55:03: %PIX-6-302006: Teardown UDP connection for faddr 80.58.4.34/370747574848

I want the output to be divided into three fields:

Field1: Mar 29 2004 09:55:03 (This is of fixed length)

Field2: PIX-6-302006 (This is of fixed length)

Field3: Teardown UDP connection for faddr 194.224.52.6/3645b4 (The remaining data )

I need a regex expression (to be used in ExtractText Processor)which is similar to Java Substring method for(start index position,end index position).

I need my attributes to be part of Nifi FlowFile attributes as to route them to different kafka output based on their value.

Hope I am clear in my question.ANy help would be highly appreciated.

P.S:The log file may vary in future.But I require that substring method of regex.

,

2 REPLIES 2

Re: How do I parse/split a line based on fixed length using regex in Nifi? ,How to substring a line based on length a line in Nifi using regex?

@Sravanthi Bellamkonda

Here is an regex that will do what you need:

^(.+): %(.*):(.*)

Add this as new property into ExtractText processor and it will add three attributes to the flow file with the pieces of the line for example:

23499-screen-shot-2017-08-08-at-93753-am.png

These attributes will be added to the file:

23486-screen-shot-2017-08-07-at-51951-pm.png

And there you go.

Re: How do I parse/split a line based on fixed length using regex in Nifi? ,How to substring a line based on length a line in Nifi using regex?

@Sravanthi Bellamkonda

Did this work for you?