title: Find and replace text using a bash script
body: <p>I have the following script which changes a password using a password file that I have piped the password to in the correct format. However, the next command needs a password file with a revised format. At the moment i just delete and re-create the file, but it would be nice to just edit it instead, im just not sure how:</p>
  
  <pre><code>sudo touch /tmp/password.txt
  sudo chmod 600 /tmp/password.txt
  sudo echo "AS_ADMIN_PASSWORD=" &gt; /tmp/password.txt
  sudo echo "AS_ADMIN_NEWPASSWORD=Pa55w0rd2" &gt;&gt; /tmp/password.txt
  sudo /opt/glassfish3/bin/asadmin --user admin --passwordfile /tmp/password.txt change-admin-password \
      --domain_name domain1
  sudo rm /tmp/password.txt
  sudo touch /tmp/password.txt
  sudo chmod 600 /tmp/password.txt
  sudo echo "AS_ADMIN_PASSWORD=Pa55w0rd2" &gt; /tmp/password.txt
  sudo /opt/glassfish3/bin/asadmin --user admin --passwordfile /tmp/password.txt enable-secure-admin
  </code></pre>