I have a file formsweb.cfg
which might look a little like this
# These match variables (e.g. %form%) in the baseHTML file. Their values
# may be overridden by specifying them in the URL query string
# (e.g. "http://myhost.example.com/forms/frmservlet?form=myform&width=700")
# or by overriding them in a specific, named configuration (see below)
[default]
# Default Oracle Forms values:
#baseHTML=base.htm
#baseHTMLjpi=basejpi.htm
width=1366
height=734
[sepwin]
separateFrame=True
lookandfeel=Generic
[debug]
serverURL=/forms/lservlet/debug
This file is missing the key-value clientDPI=96
which should be located in the [default]
section of this file.
On 100+ sites, some of the files might have clientDPI set, others might not.
I want to add the value to files which do not currently have it.
This is the sed
script that I wrote. Is there a "better" way to do it?
sed -n '/\[default\]/,/^\[/ {
/^clientDPI/q1
}' formsweb.cfg &&
sed '/\[default\]/,/^\[/ {
/^\[default\]/ {
a\
clientDPI=96
}
}' -i.bak.${RANDOM} formsweb.cfg
It checks if clientDPI exists between [default] and the next [
character. If it does it quits with 1
, otherwise, it goes to the next sed
line, which does the insert.
GNU sed version 4.1.5
You can do this with a sed script, either as you have done or using branches to only execute sed once, but as you ask for a better way, I would use a dedicated more general script, easier to adapt. After all, tomorrow you will maybe want to change "lookandfeel" to "newgeneric", or "serverURL" to "/forms/lservlet/debugmore". For example: