title: How can I execute an SQL file, and save the results to a txt file in one command?
body: <p>I am using an Ubuntu terminal. I've found answers about running .sql files, and how to save query results to an external file. How can I do them both at the same time? </p>
  
  <p>I've tried this command: <code>source /path/to/file.sql into outfile /path/to/outfile.txt</code>. </p>
  
  <p>I've tried to add <code>into outfile /path/to/outfile.txt</code> directly into <code>file.sql</code> and running <code>source /path/to/outfile.sql</code>. </p>
  
  <p>I've tried <code>mysql -u &lt;username&gt; -p &lt;database&gt; file.sql &gt; results.txt.</code> If I switch <code>file.sql</code> with something like this <code>-e "select * from myTable"</code>, then it works fine. </p>
  
  <p>How can I do this? </p>
  
  <p>EDIT: Here is <code>file.sql</code></p>
  
  <pre><code>select myID from Players where score &gt; 80;
  </code></pre>
  
  <p>It's a simple query, but if I can figure this thing out, I can try to do bigger queries.</p>