regex - Remove xml tag that contains specific value with sed -


i have configuration file

<configuration>  <property>     <name>name1</name>     <value>value1</value>     <description>desc1</description> </property>  <property>     <name>name2</name>     <value>valuetoremove</value>     <description>desc2</description>  </property>  <property>     <name>name3</name>     <value>value3</value>     <description>desc3</description>  </property>  <property>     <name>name3</name>     <value>valuetoremove</value>     <description>desc4</description>  </property>  <property>     <name>name5</name>     <value>valu5</value>  </property> </configuration> 

i want remove property tags contains value valuetoremove.

i want next output

<configuration>  <property>     <name>name1</name>     <value>value1</value>     <description>desc1</description> </property>  <property>     <name>name3</name>     <value>value3</value>     <description>desc3</description>  </property>  <property>     <name>name5</name>     <value>valu5</value>  </property> </configuration> 

next bash script removes lines value tags.

sed -i "/[<property>].*valuetoremove.*[<\/property]>/d"  "test" 

help me, please, new bash , regex.

never parse xml regexes. just wrong tools xml , variants.

really, having xml parser isn't hard nowadays. there's plenty of libraries , tools so; if you're new bash programming, why use that?

the difference os perspective bash script , e.g. python script first line,

#!/path/to/program/that/will/interpret/this/script 

and it's use script language, e.g. python, has xml library. python , lxml, it's few lines of code, , you'd pretty sure least sed-understandable xml comes out proper, long it's valid xml.

tl;dr: don't use regexes/sed parse xml. use xml parser. bash script interpreter, , there far more potent scripting languages deal such tasks.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -