Is it possible to modify an xml file in Terminal?

I got the following instructions:

sudo nano /etc/tomcat7/tomcat-users.xml

add a user who can access the manager-guiand admin-gui:

<tomcat-users> <user username="admin" password="password" roles="manager-gui,admin-gui"/> </tomcat-users>

in other words:

I need to modify xml file, rather: in xml document add new xml tag (<user>) in existing xml tag (<tomcat-users>).

I do not want to do it manually all times and I think about ability to automate this step in terminal.

What is the best way to do it?

Main problem fom me is how can I add new child xml tag in parent xml tag via terminal without manual manipulation?

I am using Ubuntu 14.10.

Solution:

 sed -i 's/<tomcat-users>/<tomcat-users>\n<user username="user" password="password" roles="manager-gui,admin-gui"\/>/' /etc/tomcat7/tomcat-users.xml
3

1 Answer

Do:

sed 's!</tomcat-users>!<user userame...../> &!' file.xml > new.xml 

or

sed -i ... file.xml

to change file.xml directly.

For more complex transformation, a tool that has xml-parser would be the indicated choice.

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like