The sed command 'H' appends from patternspace to holdspace after appending a new line into the holdspace first.
How can I append without inserting a new line into holdspace?
The sed command 'H' appends from patternspace to holdspace after appending a new line into the holdspace first.
How can I append without inserting a new line into holdspace?
There are some techniques and it depends on your goals. For example, you can use h
for the first line and remove the new line after each H
or at the end of the input ...
Removing for each append:
seq -w 10 | sed -n 'H;x;s/\n//g;x;${x;p}'
Removing at the end:
seq -w 10 | sed -n '1h;1!{H};${x;s/\n//g;p}'
The trick is using x
(exchange the contents of the hold and pattern spaces) and remove the newline.