#!/bin/bash

CSV=$1
tmpfile=$(mktemp)
function finish {
  rm -rf "$tmpfile"
}
trap finish EXIT

mv $CSV $tmpfile
cat $tmpfile | tr "\n" "\t" | sed -r 's/\t,/,/g;s/,\t/,/g' | tr "\t" "\n" > $CSV