Merge template file in bash: Difference between revisions
mNo edit summary |
mNo edit summary |
||
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 | 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}" ) | %hash = map { chomp; split /=/ } <$fh>; } s/\${(.*)}/$hash{$1} or die "missing $1"/eg' < "${SERVER_XML_FILE}" ) | ||
</geshi> | </geshi> |
Latest revision as of 07: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>