Skip to main content
Brenigan
Gold ⭐️
May 5, 2022
Solved

[Nifi] How do I split comma separrated text file not for one line, but for a several line files?

Hello! Sorry for my english. I am completely new to nifi and I am learning SplitText processor.

 

So here's the case. I have the comma separated txt file, something like this:

KeyWord, SomeInformation   <---1st line is schema.

KeyWord1, "information"

KeyWord2, "information"

KeyWord1, "another information"

KeyWord2, "another information"

 

and so on.

 

So the question is how can I split this file on a few files based on KeyWord? So the every line with KeyWord1 go to one file, every line with KeyWord2 go to another file and so on?

 

Thank you beforehand!

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
May 5, 2022

if this is a csv file where the first line is the header, you can easily split the source into two flowfiles: one containing all keyword1 rows and another containing all keyword2 rows using QueryRecord Processor. After you set you record writer\reader to CSV you can create two dynamic properties representing each keyword,  and set the query as follows:

Keyword1: SELECT * FROM FLOWFILE WHERE KeyWord like 'KeyWord1'

Keyword2: SELECT * FROM FLOWFILE WHERE KeyWord like 'KeyWord2'

3 replies

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
May 5, 2022

if this is a csv file where the first line is the header, you can easily split the source into two flowfiles: one containing all keyword1 rows and another containing all keyword2 rows using QueryRecord Processor. After you set you record writer\reader to CSV you can create two dynamic properties representing each keyword,  and set the query as follows:

Keyword1: SELECT * FROM FLOWFILE WHERE KeyWord like 'KeyWord1'

Keyword2: SELECT * FROM FLOWFILE WHERE KeyWord like 'KeyWord2'

Translate
Brenigan
BreniganAuthor
Gold ⭐️
May 6, 2022

Hello! tank you for such a detailed answer. Will it work if I have a .txt file as a source? Or should I convert it to csv somethow first?

 

Translate
SAMSAL
Platinum ⭐️⭐️⭐️
May 6, 2022

It should not matter if the format of the text inside is like csv.

Translate