'How do I insert new lines in a fixed length text file in NiFi using the ReplaceText processor with regular expressions?

I have a fixed-length text file that has only one line containing all of the 500-character records. I want to insert new lines so that the file contains only one 500-character record per line, with the number of lines being the number of records. Using the Regex, I put

(.{1000})*

in the Search Value field, and

((.{500})<shift+enter>(.{500}))*

in the Replacement Value field. The resulting file contains just the literal replacement.

((.{500}) (.{500})(.{500}) (.{500}))

What am I missing in the configuration? Is there something wrong in my regular expressions?



Solution 1:[1]

Thanks, everybody, for your help. Here is what I did to get it to work.

Search Value:

(.{500})(.{500})

Replacement Value:

$1<shift+enter>$2<shift+enter>

The $1 backreferences the first (.{500}) group, and the $2 backreferences the second (.{500}) group. The <shift+enter> introduces the newlines.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PyNerd