DEV Community

Judy
Judy

Posted on

2 1 1 1 1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more