I have files that are edited by people other than me. They contain lines that look like this:
<E> This is text </E>
I use some Bash shell scripts do a bunch of text replacement functions on these lines of text. However, in order for the text replacements to work, the format has to be exactly correct. Most of the time they are, but of course I can't rely on the editors I'm getting these files from to not make any typos.
Part of that format is that there be one space after <E>, and one space before </E>. No more, no less. So these are all incorrect:
<E>This is text </E>
<E> This is text</E>
<E> This is text </E>
<E> This is text </E>
I know I can use sed to search for specific problems, like two spaces before </E> (using # instead of / since the text I'm acting on also contains / characters):
sed -i '$ s# </E>#" </E>#g' *.txt
... but I don't know how to use it to search for an unknown number. Also, in cases where there is no space, then the character adjacent to <E> or </E> might be anything.
Bottom line, how can I search for instances of both zero spaces and of two or more spaces separated the text and <E> and </E> tags, and convert them to one space?


