Sed / regex: how to match '<' or '>' in a string

I am looking to combine less ('<') or more ('>') characters in a file using sed. I only want to combine one character

My goal is to replace them with ' <'and '> '(make sure they have free space around them so that I can easily analyze them).

For example, it will match: (without spaces in tags)

< p >Hey this is a paragraph.< /p >< p >And here is another.< /p >

.. and turn it on (note the spaces)

 < p > Hey this is a paragraph. < /p >  < p > And here is another. < /p > 



Here is what my initial (wrong) guess was:

sed 's/<{1}|>{1}/ <> /' ...


It matches the entire word / line, which is undesirable, and it is also not replaced correctly.

Anyway, any help would be appreciated! Thank!

+5
1

, :

sed 's/</ </g ; s/>/> /g' file
+5

All Articles