The GNU sed manual offers the following to join backslash-continued lines:

sed -e ':x /\$/ { N; s/\\\n//g ; bx }' FILE.txt

To demonstrate,

this \ is \ a \ long \ line and another \ line

is formatted as:

this is a long line and another line

We can achieve this in Jacinda by folding

fn go(acc, line) := option (acc+'\n'+line) [x+line] (acc ~* 1 /([^\\]*)\\/);


This is much more direct and easier to follow than the sed, despite its prolixity. However, it builds up a whole string rather than streaming; the whole output is stored in memory rather than one output line at a time.

To stream, we can use a scan and :? (mapMaybe), viz.


fn go(acc, line) := let val accStr := fromMaybe '' (acc->1) in option (None . Some (accStr+line)) [(Some (accStr+x) . None)] (line ~* 1 /([^\\]*)\\/) end;

[x->2]:?(go^(None.None) $0)

The lack of pattern-matching on tuples in Jacinda is unsatisfying.

As a parting shot, AWK:

awk 'BEGIN {RS=/[^\\]\n/} { gsub(/\\\n/, "", $0); print }' FILE.txt | head -n'-1'