Skip to main content

RouteText

Description

Routes textual data based on a set of user-defined rules. Each line in an incoming FlowFile is compared against the values specified by user-defined Properties. The mechanism by which the text is compared to these user-defined properties is defined by the 'Matching Strategy'. The data is then routed according to these rules, routing each line of the text individually.

Tags

Expression Language, Regular Expression, attributes, csv, delimited, detect, filter, find, logs, regex, regexp, routing, search, string, text

Properties

In the list below required Properties are shown with an asterisk (*). Other properties are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.

Display NameAPI NameDefault ValueAllowable ValuesDescription
Routing Strategy *Routing StrategyRoute to each matching Property Name
  • Route to each matching Property Name
  • Route to 'matched' if line matches all conditions
  • Route to 'matched' if lines matches any condition
Specifies how to determine which Relationship(s) to use when evaluating the lines of incoming text against the 'Matching Strategy' and user-defined properties.
Matching Strategy *Matching Strategy
  • Satisfies Expression
  • Starts With
  • Ends With
  • Contains
  • Equals
  • Matches Regular Expression
  • Contains Regular Expression
Specifies how to evaluate each line of incoming text against the user-defined properties.
Character Set *Character SetUTF-8The Character Set in which the incoming text is encoded
Ignore Leading/Trailing Whitespace *Ignore Leading/Trailing WhitespacetrueIndicates whether or not the whitespace at the beginning and end of the lines should be ignored when evaluating the line.
Ignore Case *Ignore Casefalse
  • true
  • false
If true, capitalization will not be taken into account when comparing values. E.g., matching against 'HELLO' or 'hello' will have the same result. This property is ignored if the 'Matching Strategy' is set to 'Satisfies Expression'.
Grouping Regular ExpressionGrouping Regular ExpressionSpecifies a Regular Expression to evaluate against each line to determine which Group the line should be placed in. The Regular Expression must have at least one Capturing Group that defines the line's Group. If multiple Capturing Groups exist in the Regular Expression, the values from all Capturing Groups will be concatenated together. Two lines will not be placed into the same FlowFile unless they both have the same value for the Group (or neither line matches the Regular Expression). For example, to group together all lines in a CSV File by the first column, we can set this value to "(.?),.". Two lines that have the same Group but different Relationships will never be placed into the same FlowFile.

Dynamic Properties

NameValueDescription
Relationship Namevalue to match againstRoutes data that matches the value specified in the Dynamic Property Value to the Relationship specified in the Dynamic Property Key.

Supports Expression Language: Yes, evaluated using FlowFile Attributes and Environment variables.

Relationships

NameDescription
originalThe original input file will be routed to this destination when the lines have been successfully routed to 1 or more relationships
unmatchedData that does not satisfy the required user-defined rules will be routed to this Relationship

Reads Attributes

This processor does not read attributes.

Writes Attributes

NameDescription
RouteText.GroupThe value captured by all capturing groups in the 'Grouping Regular Expression' property. If this property is not set or contains no capturing groups, this attribute will not be added.
RouteText.RouteThe name of the relationship to which the FlowFile was routed.

State Management

This component does not store state.

Restricted

This component is not restricted.

Input Requirement

This component requires an incoming relationship.

Example Use Cases

Use Case 1

Drop blank or empty lines from the FlowFile's content.

Configuration

"Routing Strategy" = "Route to each matching Property Name"
"Matching Strategy" = "Matches Regular Expression"
"Empty Line" = "^$"

Auto-terminate the "Empty Line" relationship.
Connect the "unmatched" relationship to the next processor in your flow.

Use Case 2

Remove specific lines of text from a file, such as those containing a specific word or having a line length over some threshold.

Configuration

"Routing Strategy" = "Route to each matching Property Name"
"Matching Strategy" = "Satisfies Expression"

An additional property should be added named "Filter Out." The value should be a NiFi Expression Language Expression that can refer to two variables (in addition to FlowFile attributes): line, which is the line of text being evaluated; and lineNo, which is the line number in the file (starting with 1). The Expression should return true for any line that should be dropped.

For example, to remove any line that starts with a # symbol, we can set "Filter Out" to ${line:startsWith("#")}.
We could also remove the first 2 lines of text by setting "Filter Out" to ${lineNo:le(2)}. Note that we use the le function because we want lines numbers less than or equal to 2, since the line index is 1-based.

Auto-terminate the "Filter Out" relationship.
Connect the "unmatched" relationship to the next processor in your flow.

System Resource Considerations

This component does not specify system resource considerations.

See Also