MxfrdA
MxfrdA

Reputation: 171

Can't change my Java .properties file with shell script

I'm looking for a way to execute a shell script that can change my Java .properties files

The .properties file is very simple :

WBURL=http://google.com

I want that script to change the address of WBURL

I've been looking on the web but i'm lost, everything is very hard ... Can't someone help me please ?

Thanks

Upvotes: 1

Views: 143

Answers (2)

user1934428
user1934428

Reputation: 22291

Since you say that this is the only entry in the properties file, it would maybe be simplest to recreate it from scratch:

echo WBURL=http://localhost >.properties

Upvotes: 0

anubhava
anubhava

Reputation: 785651

You can use awk:

awk -v val="http://localhost" 'BEGIN{FS=OFS="="} $1 == "WBURL"{$2=val} 1' file

WBURL=http://localhost

Or using sed:

val="http://localhost"

sed -i -E "s~(WBURL=).*~\1$val~" file

cat file
WBURL=http://localhost

Upvotes: 1

Related Questions