Ik zoek een manier om een xml block te vewijderen indien in een woord in het block voorkomt, dus:
Dit block moet dus weg. Ik heb alleen de algemene bash commando's tot mijn beschikking, dus geen Perl/Python. Met wat speuren kwam ik op dit uit, helaas wist dit maar 1 keer een block en dit moet ie voor alle blocks doen.
code:
1
2
3
| <filter> <hallo>zoeken</hallo> </filter> |
Dit block moet dus weg. Ik heb alleen de algemene bash commando's tot mijn beschikking, dus geen Perl/Python. Met wat speuren kwam ik op dit uit, helaas wist dit maar 1 keer een block en dit moet ie voor alle blocks doen.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
| BEGIN='<filter>'
END='<\/filter>'
REGULAREX='zoeken'
cat "/tmp/bestand.xml" | sed ":t /$BEGIN/,/$END/ { # For each line between these block markers..
/$END/!{ # If we are not at the /end/ marker
$!{ # nor the last line of the file,
N; # add the Next line to the pattern space
bt
} # and branch (loop back) to the :t label.
} # This line matches the /end/ marker.
/$REGULAREX/d; # If /regex/ matches, delete the block.
}" # Otherwise, the block will be printed. |