update .properties file with sed

in previous post we have mentioned how tu use sed link

in this short tutorial we will show how to edit .properties files using sed

lets consider this short properties file

java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url=http-remoting://localhost:8080
jboss.naming.client.ejb.context=TRUE

yes it is jndi.properties BTW

now we will use this sed script to update file

sed.exe -ri "s/java.naming.provider.url.*/java.naming.provider.url=http-remoting:\/\/127.0.0.1:8080/" jndi.properties

command i is for insert to the same file and r is for using special expresions like “^”
remember to escape special characters

after this script was executed content of jndi.properties is showed below

java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url=http-remoting://127.0.0.1:8080
jboss.naming.client.ejb.context=TRUE