I have the following Java properties file that is maintained by humans.
# file.input = /very/old/name
# file.input = /old/name
file.input = /current/name
file.input.default = /default/name
other.file.input = /current/other/name
# Other comments
other.properties = must stay the same
I must create a script that will edit this file without touching at all at the rest of the files. Therefore I cannot dump new properties in the config file.
Humans will often copy/paste a line and comment it for further use. My application must edit exclusively config file without touching any of the comments.
In this particular case, I want to edit the line file.input
to set the value to /new/name
without any commented line being touched and without any other properties being touched as well (file.input.default
, other.file.input
). My script will not keep the current line for history purpose like humans usually do. Also, I don't know the current value set to the key file.input
.
Where am I stuck? At the very beginning. I'm not a Bash expert, I rarely use it except to call commands in sequence and I use some ifs sometimes. But that's all.
I could use perl
to use regular expressions, but perl is apparently not installed on this system. So I turned to sed
, in turn, but I don't get any of this: it seems I can only replace a specific value to another. I could wrap that in the reading of the file, and rewrite it except for the expected line that I could change. Also, I would barely be able to handle human-added spaces in front of the property I want to change.
So if you have an alternative please share it, because I start to become alienated.
file.input
. Unless a human error occurs. But I shouldn't take that case in account.