title: Should I use AWK or SED to remove commas between quotation marks from a CSV file? (BASH)
body: <p>I have a bunch of daily printer logs in <code>CSV</code> format and I'm writing a script to keep track of how much paper is being used and save the info to a database, but I've come across a small problem</p>
  
  <p>Essentially, some of the document names in the logs include commas in them (which are all enclosed within double quotes), and since it's in comma separated format, my code is messing up and pushing everything one column to the right for certain records.</p>
  
  <p>From what I've been reading, it seems like the best way to go about fixing this would be using <code>awk</code> or <code>sed</code>, but I'm unsure which is the best option for my situation, and how exactly I'm supposed to implement it.</p>
  
  <p>Here's a sample of my input data:</p>
  
  <pre><code> 2015-03-23 08:50:22,Jogn.Doe,1,1,Ineo 4000p,"MicrosoftWordDocument1",COMSYRWS14,A4,PCL6,,,NOT DUPLEX,GRAYSCALE,35kb,
  </code></pre>
  
  <p>And here's what I have so far:</p>
  
  <pre><code>#!/bin/bash
  
  #Get today's file name
  yearprefix="20"
  currentdate=$(date +"%m-%d-%y");
  year=${currentdate:6};
  year="$yearprefix$year"
  month=${currentdate:0:2};
  day=${currentdate:3:2};
  filename="papercut-print-log-$year-$month-$day.csv"
  echo "The filename is: $filename"
  
  # Remove commas in between quotes.
  
  #Loop through CSV file
  
  OLDIFS=$IFS
  IFS=,
  [ ! -f $filename ] &amp;&amp; { echo "$Input file not found"; exit 99; }
  while read time user pages copies printer document client size pcl blank1 blank2 duplex greyscale filesize blank3
  do
          #Remove headers
          if [  "$user" != "" ] &amp;&amp; [ "$user" != "User" ]
          then
                  #Remove any file name with an apostrophe
  
                  if [[ "$document" =~ "'" ]];
                  then
                          document="REDACTED"; # Lazy. Need to figure out a proper solution later.
                  fi
  
                  echo "$time"
                  #Save results to database
                  mysql -u username -p -h localhost -e "USE printerusage; INSERT INTO printerlogs (time, username, pages, copies, printer, document, client, size, pcl, duplex, greyscale, filesize) VALUES ('$time', '$user', '$pages', '$copies', '$printer', '$document', '$client', '$size', '$pcl', '$duplex', '$greyscale', '$filesize');"
          fi
  done &lt; $filename
  IFS=$OLDIFS
  </code></pre>
  
  <p></p>
  
  <p>Which option is more suitable for this task? Will I have to create a second temporary file to get this done?</p>
  
  <p>Thanks in advance!</p>