replace character in a string pattern and save the change in same file

I am facing one problem, can any one please suggest me the command for the same in unix. I am using Ksh.

I have a large file with the data that looks like below.

"ROTO2-2007f","_US01","9/15/2007","9/21/2007",346492,"NICK, LCD WATCH"97,1,"NAPOLITJ ","BERGER,M Z & CO INC",0.01,

In this file, if there is a comma in the string enclosed within double quote, then that comma should be replaced with white space. For e.g. as shown above highlighted text, comma after NICK should be replaced with space.

I wrote a command to search for comma within double quote, but I am not able to replace the comma with space in the same file.

The commands I tried are as follow.

awk -F'"' '{print "Line # ", NR, $10}' /usr/users/1shahm/salesiq.dat | grep ","

  • This find the string and shows on the screen, it is working fine. But instead of replacing value it is just displaying line and line number on screen.

To replace the value, I tried following commands. But they are not working.

1> awk -F'"' '{tr "," " " }' salesiq.dat |grep ","

2> awk -F'"' '{sed -e "s/\,/ /g"}' salesiq.dat |grep ","

Can you suggest me the appropriate command which I can fit in to replace those commas. Please reply to this mail at your earliest.

With GNU sed:

sed -i.orig 's/\("[^",]\{1,\}\),\([^",]\{1,\}"\)/\1 \2/g' filename

for other seds use this:

sed 's/\("[^",]\{1,\}\),\([^",]\{1,\}"\)/\1 \2/g' filename>filename.tmp&&cp filename filename.orig&&mv filename.tmp filename

If you want "NICK, LCD WATCH" to become "NICK[ ]LCD WATCH", and
not "NICK, LCD WATCH" -> "NICK[ ][ ]LCD WATCH" ([ ] is space, note the double space b/w K and L):

sed -i.orig 's/\("[^",]\{1,\}\), *\([^",]\{1,\}"\)/\1 \2/g' filename

Hi,
Thanks for the solution. That is really working.
I tried second option. Can you please explain how that script is working. And what is the role of all those files named *.tmp , *.orig and salesiq.