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.
Add a comment
|
3 Answers
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.
2 Comments
Joe Kahla
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 ?toro2k
@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.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
Joe Kahla
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.Just use 'sed' or '>>' unix command.
This was already treated here : How can I add a line to a file in a shell script?