Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bash-skrip to delete whole xlf-tag

i try to delete an whole tag in an xlf-file like:

        <trans-unit id="test" resname="test">
            <source>Panels</source>
        </trans-unit>

Is there a way delete from string <trans-unit id="test" till string </trans-unit>?
I managed to delete two additional lines but it will be a problem on a multiline-value.

This is my current version:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sed -i.bak "/id=\"$KEY\"/,+2d" "$FILEPATH"

>Solution :

Since the file is well-indented, you can use a range pattern with sed:

sed -i.bak '/<trans-unit id="'"$KEY"'"/,/<\/trans-unit>/d' "$FILEPATH"

The command will find all lines between a line that contains <trans-unit id= + the ID in the KEY variable, and then " char, and a line that contains </trans-unit>, and then will delete the found line range(s) (due to the d flag).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading