Como deletar todos os atributos 'uuid = “* - * - * - * - *”' em um arquivo XML usando o terminal?

0

Aqui está o meu código em myfile.jrxml . Tudo que eu quero fazer é apagar tudo os atributos uuid="contained_value" .

Eu os pesquisei com grep -ir uuid * .

Como deletá-los?

<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>
    
por Kyuketsuki 09.03.2016 / 08:33

1 resposta

0

Usando sed :

sed -r 's#^(([^\s]*\s)?)uuid="[^"]*"(.*)##' file.txt
  • (([^\s]*\s)?) corresponde à parte antes da parte a ser descartada

  • uuid="[^"]*" corresponde ao bloco a ser descartado, por exemplo, uuid="...."

  • (.*) obtém o restante da linha

  • Na substituição, mantivemos apenas a parte desejada usando o padrão agrupado usado na correspondência

Exemplo:

% 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="[^"]*"(.*)##' 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>
    
por heemayl 09.03.2016 / 09:00