Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Sed and Awk (http://www.programmingforums.org/forum22.html)
-   -   Remove commas from text fields in .csv (http://www.programmingforums.org/showthread.php?t=16394)

Celsoft Aug 27th, 2008 6:53 AM

Remove commas from text fields in .csv
 
This must have been done a million times but I can't seem to find the solution :(

I have a "normal" comma-separated file (.csv) with some text fields in double-quotes. These fields MAY contain a comma, which should be changed to a space.

I want to use sed or awk (or gawk) to zap the unwanted commas, leaving the legit delimiting commas intact.

Any help appreciated ... TA
:?:

Celsoft Aug 28th, 2008 11:27 AM

Re: Remove commas from text fields in .csv
 
Just to add - Problem solved (with the help of some genii !) The following worked for me:

gawk -F\" -v OFS=\" -f awkscr.txt Infile > Outfile

with awkscr.txt containing:
{ for (i=2; i<=NF; i+=2) { gsub(","," ",$i) }; print }


All times are GMT -5. The time now is 12:01 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC