Alex Alex - 4 months ago 7
Linux Question

How to remove a space between matching words?

I've read a lot of questions about how to replace spaces from a file but I have the following problem:

I have a file like so:

<foo>"crazy foo"</foo> <bar>dull-bar</bar>

and I'm trying to remove spaces between
> <
and only those ones so the file would be like:

`<foo>"crazy foo"</foo><bar>dull-bar</bar>`

So far I've tried to remove then by using
. Sed is not working by any chance and using
tr '> <' '><'

<foo>"crazy foo"</foo><<bar>dull-bar</bar>

sed -i -e "s/> *</></g" YourFile

-i means YourFile is modified. Remove this option to test your command and display the result in shell output.

* matches n spaces.

The g at the end of sed expression means "Replace all the occurrences".