Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - How to remove any empty spaces around an equal sign

Tags:

bash

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

like image 709
RafaelGP Avatar asked Jun 06 '13 15:06

RafaelGP


2 Answers

sed -i s/\ *=\ */=/g filename

Regards

like image 199
wizard Avatar answered Sep 28 '22 12:09

wizard


This should work

sed 's/\s*=\s*/=/g' inputFile
like image 24
jaypal singh Avatar answered Sep 28 '22 12:09

jaypal singh