How can I append to holdspace from patternspace without inserting a new line into the holdspace using sed?

532 views Asked by At

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?

1

There are 1 answers

0
Ronaldo Ferreira de Lima On

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.