-1

this is my postgres connection for an Nodejs application. Can you show me how to replace "password": "******" using sed command? My current sed filter is working but that's wrong. Pls

POSTGRES_DB={"username":"postgres","password":"admin*****","database":"*****","host":"10.125.208.15","port":"5432","dialect":"postgres"}
That is my filter
's/"password":"..........."*/"password":"12345"/g'

That is output:

POSTGRES_DB={"username":"postgres","password":"12345","database":"****","host":"10.125.208.15","port":"5432","dialect":"postgres"}

1 Answers1

0

This can help:

sed 's/"password":"[^"]*"/"password":"admin123"/g'

Your password should be double quote free This command substitute (s) this phrase "password":"[^"]*" with this one "password":"admin123" globally (g) - replace all matches

Where [^"] means any character expect double quote and * means random count

lojza
  • 1,823
  • 2
  • 13
  • 23
  • @lozja that is really working with admin123. But it's not working with ${PASSWORD} variable. The output is showing like this. -- POSTGRES_DB={"username":"postgres","password":"${PASSWORD}","database":"acl-dev","host":"10.125.208.15","port":"5432","dialect":"postgres"}.. Can u help me pls? – Thaung Htike Oo Aug 17 '22 at 17:50
  • check https://stackoverflow.com/questions/19151954/how-to-use-variables-in-a-command-in-sed – lojza Aug 18 '22 at 07:29