Reputation: 31
My property file has property WLS_Home={Path to server} How to replace this with another path which i have in a script variable ?
Upvotes: 2
Views: 2179
Reputation: 2091
#!/bin/bash
new_path="/the/new/path"
sed -i "s%WLS_Home=.*%WLS_Home=$new_path%g" my_properties.file
Do not use /
as your sed
separators, or this going to throw some errors at you since you have some in your paths.
Upvotes: 2
Reputation: 212414
You can use sed:
sed '/^WLS_Home=/s@=.*$@='"$new_path"@g
Where new_path is the variable containing the new path. You will not want to use /
as the delimiter in sed
, since that is likely to appear in the path. You can overwrite the original file using shell redirections (ie sed ... file > tmp-file && mv tmp-file file
), or -i
if your sed
supports that non-standard feature.
Upvotes: 3
Reputation: 9216
Simply use sed
.
sed -i 's/Path_to_server/new_path_to_server/g' file
Upvotes: 0