0
 ...
 tomcat.javaoptions=-Djava.net.preferIPv4Stack\=true \
-Djava.net.preferIPv6Addresses\=false \
-Dcom.sun.management.jmxremote.port\=12345 \
-Djava.rmi.server.hostname=${application.hostname}
 ...

I need add new line to the end of tomcat.javaoptions with sed. I have to use regex, because I do not know how java options will look originally. i know only that it starts from tomcat.javaoptions= and can have multiple lines. Any idea?

EDITED: I need to add new line

 ...
 tomcat.javaoptions=-Djava.net.preferIPv4Stack\=true \
-Djava.net.preferIPv6Addresses\=false \
-Dcom.sun.management.jmxremote.port\=12345 \
-Djava.rmi.server.hostname=${application.hostname} \
-agentpath:/opt/agent/agent.so,name=agent
 ...

I tried it just to add only "-agentpath" but no luck

sed -i "/^tomcat.javaoptions=(.*/n*)*/s/$/ \\\\\n  -agentpath/g" file
Jaap
  • 81,064
  • 34
  • 182
  • 193
Tobymaro
  • 11
  • 3

1 Answers1

0

I don't know what the end of tomcat.javaoptions condition is, but I modify your script, so it works:

sed -r -i -e "/^tomcat.javaoptions=(.*\n*)*/s/$/ \n  -agentpath/g" File

Changes:

  • Remember to add -r parameter to sed,
  • replace your /n with \n.
Marek Nowaczyk
  • 257
  • 1
  • 5