Support Questions

Find answers, ask questions, and share your expertise
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Nifi count and content as Attribute

How do I get the count with the data into an attribute in Nifi? Is it possible to do that? If so pls guide me. TIA


@ Matt Burgess

Super Guru
@Pramod Kalvala

Could you please add more details about your question like are you expecting count number of line in the flowfile?

What I meant was, I want to convert the content in a flowfile to an attribute.

Super Guru

@Pramod Kalvala

In NiFi we are having Count Text processor which will adds the number of lines,non empty lines,characters in the text file.

Count text processor write Attributes:-

text.line.countThe number of lines of text present in the FlowFile content
text.line.nonempty.countThe number of lines of text (with at least one non-whitespace character) present in the original FlowFile
text.word.countThe number of words present in the original FlowFile
text.character.countThe number of characters (given the specified character encoding) present in the original FlowFile


If you are having content of the flowfile as below and we are having empty line as second line in the flowfile.


Once we feed this content to the Count text processor having below configs:-

Count Lines


Count Non-Empty Lines


Count Words


Count Characters


Split Words on Symbols


Output Flowfile Attributes:-


count text processor has been added line.count,nonempty lines count, character count to the flowfile.


By using ExecuteStream command processor we can run wc -l command to get the number of lines in the text document.


By using query record processor to get lines in the flowfile content

Useful links for Query record processor

If you are using QueryDatabase table,execute sql processors then we will have row.count attribute associated with the output flowfile from the which will give the number of rows has been fetched from the source.

To Convert Content as Flowfile Attribute:-

for this use case we can use Extract text processor to extract the content and store as flowfile attribute

Extract text Configs:-


Add new property with the regex (.*) i.e capture all the content and keep the content as flowfile attribute name data.

change the Enable DOTALL Mode to true if your flowfile content having new lines in it.

Most important properties are

Maximum Buffer Size1 MBSpecifies the maximum amount of data to buffer (per file) in order to apply the regular expressions. Files larger than the specified maximum will not be fully evaluated.
Maximum Capture Group Length1024Specifies the maximum number of characters a given capture group value can have. Any characters beyond the max will be truncated.

You have to increase these properties values in order of your flowfile size to get all the content of the flow file into attribute.

It's not recommended to extract all the contents and keep them as attributes, as the attributes are kept in-memory.

please refer to below link for nifi best practices and deeper

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.