I was given the task of accepting a file containing lines which might have one or occurrences of Environment variables defined as ${VAR}. I have to translate within the file all those variables into the environment variable which is defined. My solution was:
Is there an better way?perl -i -n -e ' while ($_ =~ /\${([^\$]*)}/g) { $s = "\\" . $&; $t = $ENV{$+}; s/$s/$t/e; } print $_;' file
20040517 Edit by Corion: Added formatting
In reply to Translating Env Variables by moshefr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |