0

How can I edit edit the server.xml file of a Tomcat server using the shell? I want to insert a new tag from a text file into server.xml under the <GlobalNamingResources> tag. I found many posts about the sed command, it's useful to replace a value by an other one, but in my case I want to add a tag and not replace one.

3 Answers 3

0

sed can be used also to insert lines in a file. This command append the tag foo after the GlobalNamingResources closing tag:

sed -i~ '/<\/GlobalNamingResources/a <foo></foo>' server.xml

the options -i~ makes the edit in place creating the server.xml~ backup file.

Sign up to request clarification or add additional context in comments.

2 Comments

Thats what I'm looking for, Thanks so much, but can you tell me plz what should I change to make <foo> in the <GlobalNamingResources> and not after ?
@JoeKahla removing the \/ characters only works if the <GlobalNamingResources> open tag stands on a line different from the corresponding closing tag. If they are on the same line you can't use sed.
0

Are you looking for names of editor commands?

  • pico
  • nano
  • vi
  • emacs

or if you have the shell connected to a UI

  • gedit
  • kate

and I'm sure there are various others.

1 Comment

Thx for help, but I dont want to edit the file manually, I want to make a script that paste the content of my a.txt into the server.xml of tomcat under the <GlobalNamingResources> tag.
0

Just use 'sed' or '>>' unix command.

This was already treated here : How can I add a line to a file in a shell script?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.