Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

NiFi: Convert a proprietary ASCII based format to CSV

avatar
Frequent Visitor

My data is coming in text (ASCII) files, with each line having a fixed number of fields and each field having a fixed length. I want to convert this files to CSV, like this:

Input line:

abbccc

Output line:

a,bb,ccc

I the example above "a", "bb", "ccc" are fields of fixed length. So, I always know exactly how to split the input line.

 

I looked into the ConvertRecord operator and the ScriptedReader controller service (that can be used as a record reader), but I was not able to find any example of a Python script for ScriptedReader. I found this ExecuteScript Cookbook by @mburgess, but those recipes are much more general, so I cannot use them in SciptedReader (which needs very specific objects for record processing that must be created by the script).

 

Can anyone give a basic example of a Python script that can be used in ScriptedReader to process records?

 

Alternatively, is there another way to accomplish the task (another processor)? Of course, I can use ExecuteScript processor and script the processing of complete FlowFiles in it, but my FlowFiles contain millions of records and I think this processing will be much more inefficient than SciptedReader.

1 ACCEPTED SOLUTION

avatar
Master Collaborator

You can try the ReplaceText NiFi processor withe the approached described here. That will be a clean way of doing what you want without much scripting.

View solution in original post

1 REPLY 1

avatar
Master Collaborator

You can try the ReplaceText NiFi processor withe the approached described here. That will be a clean way of doing what you want without much scripting.