Sample Header Ad - 728x90

With ed, how do you fold and unfold lines?

5 votes
3 answers
127 views
Given the following file:
foo bar baz
this and that
then I can easily "unfold" those lines with global substitution with ed(1):
g/ /s//\
/g
which gives:
foo
bar
baz
this
and
that
But what's a smooth way "fold lines"? I can't use the \n or \ pattern in a g/re/s idiom. Currently I'm using the following approach: 1. Insert spaces. 2. Join.
1
+,++s/^/ /
--,.jp
++,+++s/^/ /
--,.jp
,p
to get back:
foo bar baz
this and that
but it's pretty clunky and I wonder if there's a better way!
Asked by mbigras (3472 rep)
Feb 20, 2025, 08:48 PM
Last activity: May 25, 2025, 09:59 PM