title: Unix piping and redirection
body: <blockquote>
  <p>Assume you want to read as input the file ‘passwords.txt’, change
  every uppercase letter to a lowercase letter and every ‘$ ’ to a ‘# ’,
  then save the result back to that same file (overwriting it). How
  would you do this with the tr command? HINT: Use piping and file
  redirection.</p>
  </blockquote>
  <p>I tried these 2 commands, but they didn't work. I think the file got truncated by the system, so that the passwords.txt becomes empty after.</p>
  <blockquote>
  <p>cat passwords.txt | tr '[A-Z'!']' '[a-z'#']'</p>
  <p>tr ‘[A-Z&quot;!&quot;]’ ‘[a-z&quot;#&quot;]’ &lt; passwords.txt &gt; passwords.txt</p>
  </blockquote>
  <p>I know we can do something like writing it to a temp file and use &quot;&amp;&amp;&quot; to change the temp file name to passwords.txt . However, this is a homework problem and we haven't learn about &quot;&amp;&amp;&quot; yet, so I believe that there must be another way to do this with just piping and redirecting only.</p>