Question: I want to replace 2 same words in file(app.properties) with 2 different words using sed command.
Example:

```
mysql.host=<<CHANGE_ME>>
mysql.username=testuser
mysql.port=3306
mysql.db.password=<<CHANGE_ME>>

```

required output will be

```
mysql.host=localhost
mysql.username=testuser
mysql.port=3306
mysql.db.password=password123

```

I tried below command:

`sed -e "s/<<CHANGE_ME>>/localhost/1" -e "s/<<CHANGE_ME>>/password123/2" app.properties > /home/centos/SCRIPT/io.properties_new`

However I am getting `localhost` at both the places.

Answer: 
I'm sure it's not impossible, but also that you will not be able to figure out how it works once you find an answer. A better solution is to switch to a language which is more human-readable, so you can understand what it does.

```
awk 'BEGIN { split("localhost:password123", items, ":") }
    /<<CHANGE_ME>>/ { sub(/<<CHANGE_ME>>/, items[++i]) } 1' input_file >output_file

```

The `BEGIN` block creates an array `items` of replacements. The main script then increments `i` every time we perform a replacement, indexing further into `items` for the replacement string.
Perhaps this might help:

```
sed -e '1s/<<CHANGE_ME>>/localhost/' \
    -e '4s/<<CHANGE_ME>>/password123/' \
      app.properties > /home/centos/SCRIPT/io.properties_new

```