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.
Asked
Active
Viewed 2,396 times
0
3 Answers
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.

Olaf Kock
- 46,930
- 8
- 59
- 90
-
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 `
` tag. – Joe Kahla May 07 '13 at 08:27
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?

Community
- 1
- 1

Spawnrider
- 1,727
- 1
- 19
- 32
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.

toro2k
- 19,020
- 7
- 64
- 71
-
Thats what I'm looking for, Thanks so much, but can you tell me plz what should I change to make
in the ` – Joe Kahla May 07 '13 at 08:35` and not after ? -
@JoeKahla removing the `\/` characters only works if the `
` open tag stands on a line different from the corresponding closing tag. If they are on the same line you can't use `sed`. – toro2k May 07 '13 at 08:40