Saturday, January 27, 2024

[SOLVED] sed: replace newline within <p> </p> with space

Issue

Let's say I have the file: index.html

index.html

<p class="p">This
entry will determine the number of transmit threads, each channel
represents one thread, which can handle multiple multicast ports.
All channels are enabled by default. To temporarily disable a particular
channel, use the folowing configuration lines:</p>

How can i replace newline to space within

tag only

For example, changing index.html to:

<p class="p">This entry will determine the number of transmit threads, each channel represents one thread, which can handle multiple multicast ports. All channels are enabled by default. To temporarily disable a particular channel, use the folowing configuration lines:</p>`

Tried with,

sed -e "/<p>/s/\n/ /g" index.html

not working


Solution

Using gnu-sed:

sed -E '/<p class="p">/{:a; N; s/\n/ /g; /<\/p>/!ba;}' index.html


Answered By - anubhava
Answer Checked By - Senaida (WPSolving Volunteer)