title: Leading and trailing spaces in CSV data exported from SQL
body: <p>I am using a function to pull data from an SQL database and echo it to a file, to be subsequently e-mailed.
  However some of the fields in the CSV file (when opened with Microsoft Excel) are showing leading/trailing spaces. </p>
  
  <p>Example of the SQL:</p>
  
  <pre><code>function pull_data
  {
      sqlplus -s $user/$pass@$db &lt;&lt;EOF
      SET COLSEP ,
      SET LINESIZE 10000
      SET PAGESIZE 50000
      SET NEWPAGE NONE
      SET HEADING OFF
      SET FEEDBACK OFF
      SET ECHO OFF
      SELECT DISTINCT order_number,
                      TO_CHAR(entry_date,'DD/MM/YYYY'),
                      TO_CHAR(delivery_date,'DD/MM/YYYY'),
                      cust_name,
                      ...
  }
  
  echo "$(pull_data $a $b)" &gt; $id.csv
  </code></pre>
  
  <p>Example of the spacing (couldn't upload through Stack Overflow):</p>
  
  <p><a href="http://s3.postimg.org/ekgt9ig4f/Capture.png" rel="nofollow">http://s3.postimg.org/ekgt9ig4f/Capture.png</a></p>
  
  <p>What can be done to get the output correct i.e. no leading or trailing spaces?</p>