I'm trying to modify a file that contains sections like this:
[ policy_strict ]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ policy_loose ]
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ req_distinguished_name ]
countryName = UK
stateOrProvinceName = Scotland
localityName = Glasgow
0.organizationName = aworkplace
organizationalUnitName = eng
commonName = my.webiste.com
emailAddress = [email protected]
I want to modify the value of the common name field in the last section.
I think there should be a solution similar to this solution.
sed '/[shovel]/,/^$/ s/enabled = 0/enabled = 1/'
With the difference that, the value being replaced is not part of the expression being matched on in the sed command.
Update
Some clarification based on the comments the goal is to change the commonName field in the req_distinguished_name section only. e.g.
[ policy_strict ]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ policy_loose ]
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ req_distinguished_name ]
countryName = UK
stateOrProvinceName = Scotland
localityName = Glasgow
0.organizationName = aworkplace
organizationalUnitName = eng
commonName = adifferentvaluetotheoneintheabovesnippet
emailAddress = [email protected]