How to replace just one newline between > and <

2019-03-06 23:23发布

问题:

Lets say i have a text:

"this\n is >\n<"

and i want to replace the newline with none 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'

But it didn't work out. Any help would be appreciated.

回答1:

Escape \ with \:

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

Output:

this\n is ><