Raw Input
This one, not \, "keep this, \" this, but" replace, one
"Keep, replace", replace, keep \, and "this, that, final"
Desired Output
This one# not \, "keep this, \" this, but" replace# one
"Keep, replace"# replace# keep \, and "this, that, final"
Script and Comments
Script1 [sed]
[ 1] :loop
[ 2] s/^(([^"\\,]|"([^\\"]|\\.)*"|\\.)*),/\1#/
[ 3] t loop
Comments
  1. The DFA(Deterministic Finite Automata) to capture qualified commas is:
  2. '-r' option of sed must be used which will make sed interpret REs as Extended REs.
  3. Substitutions are performed from right to left.
Script2 [perl]
[ 1] s/\G((?:[^"\\,]|"(?:[^\\"]|\\.)*"|\\.)*),/$1#/g
Comments
  1. Substitutions are performed from left to right.