Given a file with many ENV variables.
Example: DEV.env
JavaScript
x
TRUST_STORE=/run/secret/truststore.jks
#TRUST_STORE_PASSWORD=changeit
TRUST_STORE_PASSWORD=ch@nge1t
I know the command sed "s/^/export /g"
will add export
at the beginning of each line.
But I don’t want to do this when the first character is “#”.
How can I do with sed?
Advertisement
Answer
Something like this:
JavaScript
$ sed "s/^[^#]/export &/g"
export TRUST_STORE=/run/secret/truststore.jks
#TRUST_STORE_PASSWORD=changeit
export TRUST_STORE_PASSWORD=ch@nge1t
Alternatives:
JavaScript
$ sed "/^[^#]/ s/^/export /g"
$ sed "/^#/n; s/^/export /g" #n : read the next line