DEV Community

Judy
Judy

Posted on

Convert Each Whites-space-separated Text Block into a Row #eg62

Problem description & analysis

Below is data in text file txt.txt:

this is

a

single record

 

here is the next record followed by a line with just a space

 

finally

our

last

record

We are trying to convert each block of data into a string as follows:

-> this is a single record

-> here is the next record followed by a line with just a space

-> finally our last record

Solution

Write the following p1.dfx in esProc:

Image description
Explanation:

A1   Import the txt data; @i enables returning the result set a sequence when it has only one column.

A2  Group A1’s data according to the condition that the previous member is null. Each group is headed by "->" and members in the group are connected by white spaces.

A3  Export the result set to result.txt.

SPL open source address

Download

Top comments (0)