Merge template file in bash

From EggeWiki
Revision as of 03:11, 8 January 2010 by Brianegge (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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}" ) 

</geshi>