title: Using sed to clean a CSV file
body: <p>First of all, I'd like to say that I have searched exhaustively for this solution. It is important that I use <code>sed</code> or at least a mix of *nix command line utilities to solve this. I'm dealing with, in some cases, malformed CSV files, but I'm pretty sure it's solvable. I'm missing just one piece of the puzzle.</p>
  
  <p>I'd like to build a converter from CSV to pipe. It should solve the following issues:</p>
  
  <ol>
  <li>Strip out <code>","</code> and replace with <code>|</code> </li>
  <li>Strip out <code>",</code> and replace with <code>|</code></li>
  <li>Strip out <code>,"</code> and replace with <code>|</code></li>
  <li>Strip out quotes inside quotes
  like: <code>dog,"john "bud" smith",cat</code> (becomes <code>dog|john bud smith|cat</code>)</li>
  <li>Strip out <code>,</code> which aren't between quotes and replace with <code>|</code></li>
  </ol>
  
  <p>I've completed almost all of this with a <code>sed</code> command, but I'm stumped with the commas that are within a field. There is likely a better way but I'm running out of creative thought on the topic. A proper solution will parse this string:</p>
  
  <pre><code>1234,"bill","butler","1000,p"r"airie",1234,6789
  </code></pre>
  
  <p>into</p>
  
  <pre><code>1234|bill|butler|1000,prairie|1234|6789
  </code></pre>
  
  <p>This is what I have so far:</p>
  
  <pre><code>echo '1234,"bill","butler","1000,p"r"airie",1234,6789' |
  sed -e 's/","/|/g' -e 's/,"/|/g' -e 's/",/|/g' -e 's/"//g'
  </code></pre>