Как удалить, все '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>
0
задан 9 March 2016 в 10:55

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>
0
ответ дан 29 September 2019 в 10:31

Другие вопросы по тегам:

Похожие вопросы: