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.