Reputation: 1889
I have an xml file which I'm trying to minimise using a bash script.
After removing any indentation, some part of the file looks like this:
<layer name ="dotted_line"
align ="topleft"
edge ="topleft"
handcursor ="false"
keep ="true"
url ="%SWFPATH%/include/info_btn/dotted_line.png"
zorder ="15"
/>
I'd like to remove any empty spaces before and after the equal sign, so it'd look like:
<layer name="dotted_line"
align="topleft"
edge="topleft"
handcursor="false"
keep="true"
url="%SWFPATH%/include/info_btn/dotted_line.png"
zorder="15"
/>
Any ideas how can achieve this?
Thanks
Upvotes: 5
Views: 2012
Reputation: 3791
You should first try to see if xmllint --format isn't already doing everything you need:
xmllint --format OLDFILE.xml > NEWFILE.xml
The big advantage of this approach:
name = value
with name=value
but will get rid of many other extra spaces, and indent "neatly" and tersely.another way, if you are SURE that the name ="value" are each alone on their own line:
export _tab_="$(printf '\011')"
sed -e "s/^[ ${_tab_}]*[a-zA-Z0-9_-]\([a-zA-Z0-9_-]*\)[ ${_tab_}][ ${_tab_}]*=[ ${_tab_}][ ${_tab_}]*/\1=/" OLDFILE.xml > NEWFILE.xml
Upvotes: 0
Reputation: 360782
use tr
?
$ echo 'hello there' | tr -d "[:space:]"
hellothere
$
Of course this'll trash ALL spaces in the file, which may be a bit too much.
Upvotes: 1