Use output of one command as replacement text in sed

Viewed 4050

I have a .env file with a bunch of key-value pairs like so:

NAME=John Doe
CITY=Timbuctoo
CSS=<some value>
PORT=3000

It is the third line I'm trying to change programmatically. is a dynamically-generated md5 hash and each time I run the command, it needs to be replaced by a new hash. This is how I'm generating the hash:

$ date +%s | md5sum | cut -d' ' -f 1

And I wish to use the output of the above command as the replacement text when using sed. But can't figure out how to make it work. The following is the solution I have so far which is far from complete:

$ date +%s | md5sum | cut -d' ' -f 1 | sed -i.bak 's/^\(CSS=\).*/replacement/' ~/nano/.env

What should put in place of "replacement" to ensure the original value gets replaced by the value returned by cut?

2 Answers
Related