Merge template file in bash: Difference between revisions

From EggeWiki
m (Created page with '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 and uses perl to parse in a property file with…')
 
mNo edit summary
Line 2: Line 2:


<geshi lang="bash">
<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}" ) \
       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>
</geshi>


[[Category:Perl]]
[[Category:Perl]]
[[Category:Bash]]
[[Category:Bash]]

Revision as of 03:01, 8 January 2010

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 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>