0

I need to replace my tomcat.conf string content using linux command

Example: I am having a text like below

CATALINA_HOME="/usr/share/tomcat" 
JAVA_HOME="/apps/opt/jdk" 

in tomcat.conf file

I need to replace like below

JAVA_HOME="apps/opt/Java/jdk-1.7"

Only JAVA_HOME content need to replace

Please help me resolve this

NOTE : If it is a single line command, it ll be very useful

choroba
  • 231,213
  • 25
  • 204
  • 289
  • show your efforts – RomanPerekhrest Jul 03 '17 at 12:32
  • Should be easy with `sed`. What have you tried? – choroba Jul 03 '17 at 12:34
  • I tried with sed comment like this sed 's/\(JAVA_HOME=\))\(*\)"/apps/opt/Java/jdk-1.7" tomcat.conf | tee tomcat.conf – Rajesh Kumar Duraisamy Jul 03 '17 at 12:38
  • @RajeshKumar, that code will sometimes result in an empty file. Pipelines start all components at the same time, so `tee outfile` is started (truncating `outfile` so it can start writing to it) at the exact time as your `sed` is, so which process wins the race (whether `sed` reads the data before `tee` truncates that data) is quite unpredictable. – Charles Duffy Jul 03 '17 at 12:39
  • [BashFAQ #21](http://mywiki.wooledge.org/BashFAQ/021) covers this class of questions quite well, btw. – Charles Duffy Jul 03 '17 at 12:41
  • @RajeshKumar, ...beyond that, it's just not a valid regex. Perhaps you want `sed -e 's@^JAVA_HOME=.*@JAVA_HOME=/apps/opt/Java/jdk-1.7@'` for that expression, *if* you're going to use `sed`? (The nonstandard `-i` argument can be used to ask sed to do an in-place replacement itself, but exactly how to do that varies between GNU and BSD platforms, whereas -- as BashFAQ #21 discusses -- POSIX-standardized alternatives are also available). – Charles Duffy Jul 03 '17 at 12:43

0 Answers0