I am trying to build a script that use "sed" to do the following :
- Search for files ending with .config (ie: test.js.config) in the current directory and all under it.
- Replace a string with another one (ie: {TEST} -> 50)
- Save the result in a new file that does not have the .config at the end (ex: test.js)
- Delete the original .config file (ie: test.js.config)
It would be great if it would be able to use another file that has the "string to search" with a "string to replace", like a dictionnary :
{TEST} = 50
{FIRST_NAME} = Alex
You can put a bunch of sed
s///commands in a file:If you have the following config input:
$ cat test.js.config
alert({TEST})
alert({FIRST_NAME})
The result will be:
The syntax is not great, but it is neither horrendous 🙂
OTOH, if you really want to use the bracket syntax in the replacing file…
… and the key-value pair in the replacement file…
…you can write a sed command to change the key-value pair in sed replacements…
…and use this command in the real replacement: