Как удалить все атрибуты `uuid="*-*-*-*-*"` в файле XML с помощью терминала?
Вот мой код в myfile.jrxml
, Все, что я хочу сделать, это удалить всеuuid="contained_value"
атрибутов.
Я искал их с grep -ir uuid *
,
Как их удалить?
<band height="50">
<line>
<reportElement x="8" y="10" width="543" height="1" uuid="cab05ad8-976b-42c9-a158-a6260dd630e1"/>
</line>
<line>
<reportElement x="11" y="38" width="543" height="1" uuid="b673c65e-71e4-4e1c-81e0-ece92c094871"/>
<graphicElement>
<pen lineWidth="2.75"/>
</graphicElement>
</line>
<line>
<reportElement x="11" y="38" width="543" height="1" uuid="f87d4dc0-134f-41ae-a828-bca4169d5eb0"/>
<graphicElement>
<pen lineWidth="2.75"/>
</graphicElement>
</line>
<staticText>
<reportElement x="343" y="13" width="100" height="20" uuid="58c3c4c4-f76e-48a0-897b-2bf129d1fd01"/>
<text><![CDATA[Amount /Day]]></text>
</staticText>
<textField>
<reportElement x="449" y="13" width="100" height="20" uuid="8f2e99b5-aa81-49d9-bd0c-a763c37d926e"/>
<textFieldExpression><![CDATA[$V{day_total}]]></textFieldExpression>
</textField>
</band>
1 ответ
С помощью sed
:
sed -r 's#^(([^\s]*\s)?)uuid="[^"]*"(.*)#\1\3#' file.txt
(([^\s]*\s)?)
соответствует части перед частью, которая будет отброшенаuuid="[^"]*"
соответствует блоку, который должен быть отброшен, т.е.uuid="...."
(.*)
получает остальную часть линииВ замене мы сохранили только желаемую часть, используя сгруппированный образец, используемый в сопоставлении
Пример:
% cat file.txt
<band height="50">
<line>
<reportElement x="8" y="10" width="543" height="1" uuid="cab05ad8-976b-42c9-a158-a6260dd630e1"/>
</line>
<line>
<reportElement x="11" y="38" width="543" height="1" uuid="b673c65e-71e4-4e1c-81e0-ece92c094871"/>
<graphicElement>
<pen lineWidth="2.75"/>
</graphicElement>
</line>
<line>
<reportElement x="11" y="38" width="543" height="1" uuid="f87d4dc0-134f-41ae-a828-bca4169d5eb0"/>
<graphicElement>
<pen lineWidth="2.75"/>
</graphicElement>
</line>
<staticText>
<reportElement x="343" y="13" width="100" height="20" uuid="58c3c4c4-f76e-48a0-897b-2bf129d1fd01"/>
<text><![CDATA[Amount /Day]]></text>
</staticText>
<textField>
<reportElement x="449" y="13" width="100" height="20" uuid="8f2e99b5-aa81-49d9-bd0c-a763c37d926e"/>
<textFieldExpression><![CDATA[$V{day_total}]]></textFieldExpression>
</textField>
</band>
% sed -r 's#^(([^\s]*\s)?)uuid="[^"]*"(.*)#\1\3#' file.txt
<band height="50">
<line>
<reportElement x="8" y="10" width="543" height="1" />
</line>
<line>
<reportElement x="11" y="38" width="543" height="1" />
<graphicElement>
<pen lineWidth="2.75"/>
</graphicElement>
</line>
<line>
<reportElement x="11" y="38" width="543" height="1" />
<graphicElement>
<pen lineWidth="2.75"/>
</graphicElement>
</line>
<staticText>
<reportElement x="343" y="13" width="100" height="20" />
<text><![CDATA[Amount /Day]]></text>
</staticText>
<textField>
<reportElement x="449" y="13" width="100" height="20" />
<textFieldExpression><![CDATA[$V{day_total}]]></textFieldExpression>
</textField>
</band>