Here is a short script that can do this:
cut -d= -f 1 props.txt | tr '[:lower:]' '[:upper:]' | tr '.-' '_' > $tmp1
cut -d= -f 2 props.txt > $tmp2
paste -d= $tmp1 $tmp2 > output.props
sed -i 's/ *= */=/' output.props
sed -i 's/^/export /' output.props
rm $tmp1 $tmp2
This script works in the following manner. Two temporary files are generated using
mktemp. The input properties file is split on the '=' character and the two respective fields are sent to these two files.
On the first field (the property name), the
tr command is applied twice. Once for lowercase-to-uppercase conversion, once for changing the special characters to an underscore. The field values are only written to the temporary file after these changes.
Once the processing is done, the
paste command is used to the put the fields back together into a single file, output.props. Then, two
sed commands are used. The first one removes any space characters around the '=' character, which would otherwise be a syntax error for the
export command. The second
sed command is used to prefix the string 'export ' to each line. Finally, the two temporary files are cleaned up.
$ cat output.props
Once the output file is generated, source it to actually set the variables in the environment. One of the two following syntaxes may be used for this: