Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top