Question: I need to to iterate over the files in a directory and perform the following replacement.

**Before:**

> 
> Hello ${USER\_NAME}, you live at
>  ${HOME\_ADDRESS}. It is now ${TIME}
> 
> 
> 

**After:**

> 
> Hello ${userName}, you live at
>  ${homeAddress}. It is now ${time}
> 
> 
> 

The number of different tokens that appear within ${} is large, so it's not really feasible to run:

```
find . -name '*' -exec sed -i 's/${USER_NAME}/${userName}/g' {} \;
find . -name '*' -exec sed -i 's/${TIME}/${time}/g' {} \;

```

etc.

I'm hoping it's possible to perform this replacement using a single command, that looks something like:

```
find . -name '*' -exec sed 's/XXX/YYY/g' {} \;

```

But I can't figure out what to substitute for XXX and YYY. Is it possible to do this in a single command?

Cheers,
Donal

Answer: 
Formatted for clarity:

```
sed -i '/^Hello/ { s/\$\{USER_NAME\}/\$\{userName\}/g 
                   s/\$\{HOME_ADDRESS\}/\$\{homeAddress\}/g 
                   s/\$\{TIME\}/\$\{time\}/g
                  }'

```

Where `/^Hello/` identifies the lines you wish to act on (make it more specific if needed) and the rest substitutes each variable name. 

---

If writing this into a script consider the use of a HERE document to keep the formatting and make it easier to read and update...
The answer above works really well. For completeness, I might add that you can do:

```
sed '/^Hello/ { s/\$\{USER_NAME\}/\$\{userName\}/g' <filename> \
   | sed 's/\$\{HOME_ADDRESS\}/\$\{homeAddress\}/g' \
   | sed 's/\$\{TIME\}/\$\{time\}/g'

```

They're functionally identical (except that mine dumps to stdout; you'll have to put it somewhere (but you get to keep the original in case, like e, you mess up regularly on your regexps). I like my formulation just because I can start with the one sed command, then add on more with

```
!! | sed 'yet-enother-regexp'

```

Arrow keys? vi-mode? Who needs that stuff? :)