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

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:

A

1

=file("txt.txt").import@i()

2

=A1.group@i(~[-1]==null).("->    "/~.select(~).concat(" "))

3

=file("result.txt").export(A2)

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.

Q & A Collection

https://stackoverflow.com/questions/56655536/java-streams-and-multiline-records