Merge template file in bash

From EggeWiki
Jump to navigation Jump to search

I wanted to substitute some parameters in an xml file prior to feeding it to a Java program. The following one liner works in bash. In invokes a perl one liner using process substitution and uses perl to parse in a property file with '=' delimiters. All ${} are substituted, and any missing params cause an error to be thrown.

<geshi lang="bash">

     java -xmlconfig <(perl -pne 'BEGIN { open my $fh, $ENV{SERVER_PROPERTIES_FILE} or die $!; \
%hash = map { chomp; split /=/ } <$fh>; } s/\${(.*)}/$hash{$1} or die "missing $1"/eg' < "${SERVER_XML_FILE}" )