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
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
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.
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 [http://tldp.org/LDP/abs/html/process-sub.html 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">
<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]]

Latest revision as of 03:11, 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. 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>