All Articles

How to Remove All Lines Except for the First Line in a Flat File with RegEx

One possible way to remove all of the lines except for the first line in a flat file is by using a regular expressions (regex). To do this, add a data process shape to the canvas. Next, add a processing step and select Search/Replace. Within the Text To Find field add ”([\r][\n]|[\n]).*” but without the quotes. Then make Replace With blank. The regex will find everything after the first line break and will replace it with a no character string. Linux usually uses \n (a line feed) and Windows usually uses \r\n (a carriage return and line feed). The regex allows for either Windows’ or Linux’s end of line characters to be used.

Data Process Regex

Figure 1. Example of how to setup a data process shape to remove all but the first line in a flat file.

Article originally posted at Boomi Community.

Published Apr 29, 2021

Developing a better world.© All rights reserved.