title: Using awk how do I replace a word in a file with unique values?
body: <p>This is the file I want to use:</p>
  
  <p>test.txt:</p>
  
  <pre><code>apiVersion: v1
  data:
    app_username: something
    app_password: {{RANDOM}}
    another_app_username: something
    another_app_password: {{RANDOM}}
  </code></pre>
  
  <p>I currently have this bash script:</p>
  
  <p>test.sh:</p>
  
  <pre><code>random(){
    printf $(openssl rand -base64 15) | openssl base64
  }
  
  export -f random
  
  awk '{ 
    gsub(/{{RANDOM}}/, system("random"), $0); printf
  }' test.txt
  </code></pre>
  
  <p>This outputs:</p>
  
  <pre><code>TVQ3K0hmZmZGMTBPYW9BT0pIbzc=
  apiVersion: v1QlBXZzVFNXFUdzBXNzdwdmtWc2w=
  data:eDJDcUZKU1U2d1EwaWc5cVhQYUY=
    app_username: somethingay93S3NTNStQKy9jVXFOUHBSZnY=
    app_password: 0NTBJTUpueWRuU1VZYmlWSXZwS0k=
    another_app_username: somethingdzdCWXltMytSUWRFY2RicVh5ZkI=
    another_app_password: 0%
  </code></pre>
  
  <p>As you can see, it's doing <em>something</em>. It's removing {{RANDOM}} but not replacing it. Instead it's putting the output of the 'random' function at the end of every new line.</p>