Arun
Arun

Reputation: 57

Delete the whole xml tag using the sed command

I want to delete the whole xml tag including the content . But only the first 2 lines are getting deleted. sed or awk is okay

 <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
                   maxTotal="100" maxIdle="30" maxWaitMillis="10000"
                   username="javauser" password="javadude" 
                             driverClassName="com.mysql.jdbc.Driver"
                             url="jdbc:mysql://localhost:3306/javatest"/>

After trying out the sed command sed -i "/Resource/,/[^\/>]/d" test.xml

I am left over with

  username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/javatest"/>

Upvotes: 1

Views: 611

Answers (2)

Cyrus
Cyrus

Reputation: 88563

With xmlstarlet:

xmlstarlet edit --delete '//path/to/your/tag' file.xml

Upvotes: 1

LMC
LMC

Reputation: 12662

This will do what you want

sed '/<Resource /{:a;N;/\/>/!ba};/<Resource/d' test.html

Upvotes: 0

Related Questions