nomazoma49 nomazoma49 - 1 year ago 63
Bash Question

How to remove only one newline between > [greater than] and < [less than] in unix

Lets consider that there is a text in the following format:

"this\n is >\n<"

and i want to truncate the newline only between > and < which will result in:

"this\n is ><"

How to achieve this ?

I tried using the following:

echo "this\n is >\n<" | sed -e 's/>\n<//g'


echo "this\n is >\n<" | sed -e 's/>\\n</></g'

But none of them work out. Any suggestions from genius minds ?

Answer Source

This might work for you (GNU sed):

sed ':a;N;s/>\n</></;ta;P;D' file

Read two lines into the pattern space and if the newline is between > and < remove it. Then print and delete the first line and repeat.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download