How to remove '-' for date fields alone in a file

Hi,
I have a scenario like, I need to replace a hyphens(-) for date field alone in the file.
I have minus(-) sign for other fields it should remain as such, only for date fields hyphens must be removed. Please find the content for the file below:

sample.txt:
-----------

KSA,B12467428,2010-06-04,2010-06-04,2011-06-04,ITI, ,N,2011-06-04,AT,IFGC,13097573, ,001,OUT,1, 0000000000627.00,   ,   ,   , 0000000000000.00,     ,,, -0000000000627.00, 0000000000000.00, 0000000000532.95, 0000000000094.05, 00000.1500, 0000000000000.00
KSA,M03201053,2009-06-11,2009-06-11,2010-06-11,IMP,P,R,2010-06-11,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00,   ,   ,   , 0000000000000.00,     ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000, 0000000000000.00

Expect results from the sample.txt: (only for date values hyphens(-) are removed)
---------------------------------------------------------------

KSA,B12467428,20100604,20100604,20110604,ITI, ,N,20110604,AT,IFGC,13097573, ,001,OUT,1, 0000000000627.00,   ,   ,   , 0000000000000.00,     ,,, -0000000000627.00, 0000000000000.00, 0000000000532.95, 0000000000094.05, 00000.1500, 0000000000000.00
KSA,M03201053,20090611,20090611,20100611,IMP,P,R,20100611,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00,   ,   ,   , 0000000000000.00,     ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000, 0000000000000.00

Please help me to achieve this using unix command, because as i am new bee to scripting. :slight_smile:
Thanks very much in advance.
KK

$ ruby -F"," -ane '2.upto(4){|x|$F[x].gsub!("-","");$F[7].gsub!("-","")}; print $F.join(",")' file

Try...

sed 's/\(....\)-\(..\)-\(..\)/\1\2\3/g' file1 > file2
$
$
$ # show the content of the input file "f1"
$ cat -n f1
     1  KSA,B12467428,2010-06-04,2010-06-04,2011-06-04,ITI, ,N,2011-06-04,AT,IFGC,13097573, ,001,OUT,1, 0000000000627.00, , , , 0000000000000.00, ,,, -0000000000627.00, 0000000000000.00, 0000000000532.95, 0000000000094.05, 00000.1500, 0000000000000.00
     2  KSA,M03201053,2009-06-11,2009-06-11,2010-06-11,IMP,P,R,2010-06-11,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00, , , , 0000000000000.00, ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000, 0000000000000.00
     3  2009-09-09,KSA,M03201053,2009-06-11,2010-06-11,IMP,P,R,2010-06-11,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00, , , , 0000000000000.00, ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000, 0000000000000.00
     4  KSA,M03201053,2009-06-11,2009-06-11,2010-06-11,IMP,P,R,2010-06-11,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00, , , , 0000000000000.00, ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000,2010-12-31
$
$
$ # run the Perl one-liner to transform the dates
$ perl -lne 's/(^|,)(\d{4})-(\d\d)-(\d\d)/$1$2$3$4/g; print' f1
KSA,B12467428,20100604,20100604,20110604,ITI, ,N,20110604,AT,IFGC,13097573, ,001,OUT,1, 0000000000627.00, , , , 0000000000000.00, ,,, -0000000000627.00, 0000000000000.00, 0000000000532.95, 0000000000094.05, 00000.1500, 0000000000000.00
KSA,M03201053,20090611,20090611,20100611,IMP,P,R,20100611,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00, , , , 0000000000000.00, ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000, 0000000000000.00
20090909,KSA,M03201053,20090611,20100611,IMP,P,R,20100611,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00, , , , 0000000000000.00, ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000, 0000000000000.00
KSA,M03201053,20090611,20090611,20100611,IMP,P,R,20100611,ME,IFGC,06490230, ,013,XLL,1,-0000000000657.00, , , , 0000000000000.00, ,,,-0000000000657.00, 0000000000000.00,-0000000000545.31,-0000000000111.69, 00000.0000,20101231
$
$

tyler_durden

sed 's/\([0-9]\)-/\1/g' infile