0

I have a file which has below path-

JVM == /home/user/tools/jdk/bin/java

I want to replace "/home/user/tools/jdk/bin/java" with "/apps/java/bin"

I use below command in chef resource but it does not work- sed -i -e 's//home/user/tools/jdk/bin/java//apps/bin/java/' testfilename

I get below error- STDERR: sed: couldn't open file ser/tools/jdk/bin/java//apps/bin/java/: No such file or directory

user6378152
  • 257
  • 2
  • 6
  • 11
  • You need to escape to forward slashes: `\/` – Aurélien Gasser May 17 '17 at 17:32
  • Have a look at [Chef::FileEdit](http://stackoverflow.com/questions/14848110/how-can-i-change-a-file-with-chef). Don't call `sed` from Chef. Please post your code in your future questions. – StephenKing May 17 '17 at 17:50
  • yes I tried with that too- sed -i -e 's/\/home\/user\/tools\/jdk\/bin\/java/\/apps\/bin\/java/' testfilename – user6378152 May 17 '17 at 17:53
  • If the file contains parameter like "JVM == /home/user/tools/jdk/bin/java" in a single line then you can directly replace the line. If not, can you please put the whole line which needs to be updated. – Mrigesh Priyadarshi May 17 '17 at 19:06
  • Is it `apps/bin/java/` or `apps/java/bin`? – Beta May 18 '17 at 00:32
  • Hi Mrigesh, how can I replace the whole line with JVM == /apps/java/bin ? – user6378152 May 18 '17 at 00:34
  • Stephen,Below is the code I am using. I also tried using the same code with "execute" resource but same error- bash 'Changing path in filename.txt' do code <<-EOH cd #{full_app_path}/Applications/#{app_name}.woa.#{woa_build_version}/Contents/UNIX sed -i -e "s/\/home\/user\/tools\/jdk\/bin\/java/\/apps\/bin\/java/" filename.txt EOH end – user6378152 May 18 '17 at 00:36

1 Answers1

0

Check out the line cookbook for this kind of operation.

coderanger
  • 52,400
  • 4
  • 52
  • 75