Michael Hegner Michael Hegner - 4 months ago 10
Bash Question

Shell Script Edit Files Line

I am not that good on linux shell script and I need little help.

I want to edit a file via script (finding the line and edit).

The Original line is:


# JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=< hostname >"


I want to uncomment and replaye hostname with 127.0.0.1


JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=127.0.0.1"

Answer

You can refer to the set command, change the filename with the name you are working at,

sed -i 's@# JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=< hostname >"@JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=127.0.0.1"@' filename