title: sed command in bash script to change YAML file
body: <p>I have a YAML file like below:</p>
  <pre><code>server:
    scheme: http
    host: localhost
    port: 8080
    context: myctx
  
  report:
    output-dir-base: /tmp
  ---
  spring:
    config:
      activate:
        on-profile: local
  vertica:
    datasource:
      jdbc-url: jdbc:vertica://server:65534/database
      username: user
      password: db_pass
  
  da-config:
    user: username
    password: da_pass
    da-host:
      scheme: http
      server: server
      port: 65535
  </code></pre>
  <p>From a bash script I want to replace Vertica password with a given value, let's say &quot;first_pass&quot; and da password with &quot;second_pass&quot;.</p>
  <p>I tried this but didn't work.</p>
  <pre><code>sed '/^vertica:\([[:space:]]*password: \).*/s//\1first_pass/' common-properties.yaml
  </code></pre>
  <p>Can this be helped with, please?</p>
  <h1>UPDATE:</h1>
  <p>This is what I did to handle the situation. In the bash script file</p>
  <pre><code>DB_PASSWORD=&quot;first_pass/here&quot; ## I realized later that the password could contain a '/' char as well
  DA_PASSWORD=&quot;second_pass&quot;
  
  sed -i '/vertica:/{n;n;n;n;s/\(password\).*/\1: '&quot;${DB_PASSWORD//\//\\/}&quot;'/}' my.yaml  ## backslash-escape the '/' in the variable
  
  sed -i '/da-config:/{n;n;s/\(password\).*/\1: '&quot;${DA_PASSWORD//\//\\/}&quot;'/}' my.yaml
  </code></pre>