[英]Bash - How to remove any empty spaces around an equal sign
我有一個xml文件,我試圖使用bash腳本最小化。
刪除任何縮進后,文件的某些部分如下所示:
<layer name ="dotted_line"
align ="topleft"
edge ="topleft"
handcursor ="false"
keep ="true"
url ="%SWFPATH%/include/info_btn/dotted_line.png"
zorder ="15"
/>
我想在等號之前和之后刪除任何空格,所以它看起來像:
<layer name="dotted_line"
align="topleft"
edge="topleft"
handcursor="false"
keep="true"
url="%SWFPATH%/include/info_btn/dotted_line.png"
zorder="15"
/>
任何想法怎么能實現這個?
謝謝
sed -is/\\ *=\\ */=/g filename
問候
這應該工作
sed 's/\s*=\s*/=/g' inputFile
使用tr
?
$ echo 'hello there' | tr -d "[:space:]"
hellothere
$
當然這會丟棄文件中的所有空格,這可能有點太多了。
您應該首先嘗試查看xmllint --format是否還沒有完成您需要的所有操作:
xmllint --format OLDFILE.xml > NEWFILE.xml
這種方法的最大優點是:
name = value
與name=value
,但將擺脫許多其他多余的空格,和縮進“整齊”和簡潔。 換句話說,如果你確定name =“value”各自獨立:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.