The following solution is brute force, but easy to understand and fairly stable ... First, gsub will change $ ModuleEins to ModuleEins, and then change all ModuleEins. Using "\" to escape certain characters is required because the first gsub parameter is an extended regular expression. In this mini-language, the characters "$", "{" and "}" are the default metacharacters and are interpreted by gsub with a special meaning.
$ x='(ModuleEins = WertA | ${ModuleEins} = WertB | ModuleEins = WertB)' $ echo $x | awk '{ gsub(/\$\{ModuleEins\}/, "ModuleEins"); gsub(/ModuleEins/, "${ModuleEins}") } 1' (${ModuleEins} = WertA | ${ModuleEins} = WertB | ${ModuleEins} = WertB)
Implementing SED may be the best way to keep it short:
$ echo $x | sed 's/\${ModuleEins}/ModuleEins/g; s/ModuleEins/${ModuleEins}/g' (${ModuleEins} = WertA | ${ModuleEins} = WertB | ${ModuleEins} = WertB)
Note that in the above example, escaping rules are different because AWK uses extended regular expressions for the search pattern, and SED uses basic / traditional regular expressions. The difference between the two languages of regular expressions is related to the acceleration of metacharacters, and this is described in the egrep (3) manual (search for "Basic and advanced regular expressions").
source share