shellawksedbosh

awk quoting program text


if I run:

awk '/-jar org.eclipse.osgi.jar --launcher.suppressE/ {print "-Dcom.abc.service.gw.enableValidation=false \\"}1' rest_gw.sh >> new_gw.sh

the command inserts a new line above line -jar org.eclipse.osgi.jar --launcher.suppressE

-Djava.security.properties=/var/vcap/packages/helpers/data.properties \
-Dcom.abc.service.gw.enableValidation=false \  <<<<<<<<<<<<<<<<<<<<<<<<<
-jar org.eclipse.osgi.jar --launcher.suppressErrors -consoleLog &

If I run the following command, it gives: awk: line 1: runaway string constant "-Dcom.abc. ...

bosh -d test-105 ssh service/0 -c 'sudo /usr/bin/awk "/-jar org.eclipse.osgi.jar --launcher.suppressErrors/ {print \"-Dcom.abc.service.gw.enableValidation=false \\\"}1" /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh'

Tried:

bosh -d test-105 ssh service/0 -c 'sudo /usr/bin/awk '\'/-jar org.eclipse.osgi.jar --launcher.suppressErrors/ {print \"-Dcom.abc.service.gw.enableValidation=false \\\"}1\' /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh'

no luck so far. can someone suggest the correct way to do it? TYA!

EDIT:

sed command as recommended:

bosh -d test-105 ssh service/0 -c 'sudo sed '/-jar org.eclipse.osgi.jar --launcher.suppressE/i -Dcom.abc.service.gw.enableValidation=false \\' /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh'

unknown flag launcher.suppressE/i'

This worked finally:

bosh -d test-105 ssh service/0 -c "sudo sed '/-jar org.eclipse.osgi.jar --launcher.suppressErrors -consoleLog/i -Dcom.abc.service.gw.enableValidation=false \\\' /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh"

Solution

  • I strongly suggest use sed command insert your line as:

    sed  '/-jar org.eclipse.osgi.jar --launcher.suppressE/i -Dcom.abc.service.gw.enableValidation=false \\' rest_gw.sh >> new_gw.sh
    

    It is cleaner and simple.