Subject: bug#35020: I apologize it's not the right place, but I need answer

From: Assaf Gordon <[email-masked]>
Date: Wed, 27 Mar 2019 16:23:48 -0600

tags 35020
close  35020
stop

Hello,

On 2019-03-27 7:25 a.m., Budi wrote:
> How can sed regex substitution replacement be the Hold space content ?
> I do need the answer so really appreciate. Thanks much!

s/// command operate on the pattern space.
But you can use the 'x' command the exchange the content
of the hold and pattern space, and then use "s///".

Example:

This sed program accumulates even numbers
into the hold space (H), and prints the odd values (p).
At the end of the input ($), it fetches back the hold space content (x),
performs a regex substitution on it (s) and prints it (p).

$ seq 0 5 50 | sed -n '/0$/H;/5$/p;${x;s/\n/===/g;p}'
5
15
25
35
45
===0===10===20===30===40===50

regards,
  - assaf