如何编辑XML文件以通过shell脚本更改所有数字,其中原始点除以1.3?

时间:2017-02-15 06:02:53

标签: python linux bash perl shell

原始xml:

<dimen name="placeHolderXNot10">20dp</dimen>
<dimen name="placeHolderYNot10">35dp</dimen>

<dimen name="placeHolderXFor10">15dp</dimen>
<dimen name="placeHolderYFor10">35dp</dimen>

<dimen name="rightNot10">40dp</dimen>
<dimen name="topNot10">75dp</dimen>
<dimen name="bottomNot10">15dp</dimen>

**将数字除以1.3后,**

<dimen name="placeHolderXNot10">15.38dp</dimen>
<dimen name="placeHolderYNot10">26.92dp</dimen>

<dimen name="placeHolderXFor10">15.38dp</dimen>
<dimen name="placeHolderYFor10">26.92dp</dimen>

<dimen name="rightNot10">30.76dp</dimen>
<dimen name="topNot10">57.69dp</dimen>
<dimen name="bottomNot10">11.53dp</dimen>

我有更多的xml文件,我想在其中更改密度像素。

1 个答案:

答案 0 :(得分:1)

如果您对awk解决方案持开放态度:

awk -v FS='[^>]>|<'  '/</{x=$3/1.3"dp";gsub($3,x)}1' inputfile

<dimen name="placeHolderXNot10">15.3846dp</dimen>
<dimen name="placeHolderYNot10">26.9231dp</dimen>

<dimen name="placeHolderXFor10">11.5385dp</dimen>
<dimen name="placeHolderYFor10">26.9231dp</dimen>

<dimen name="rightNot10">30.7692dp</dimen>
<dimen name="topNot10">57.6923dp</dimen>
<dimen name="bottomNot10">11.5385dp</dimen>