Managing sequence to make unique record

Hi Everyone,

Using shell script i am getting final file as attached below. In this 4th column value should be unique using any sequence.
for instance I've 1_13020_SSGM which is appearing 6 times in file and i should change it like 1_13020_SSGM_1,1_13020_SSGM_2,....1_13020_SSGM_6.
Can someone please provide some idea on this?
Input file
05112009,601,Excel,1_13020_DWS,1,999001
05112009,601,Excel,1_11020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_11020_NEWE,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
Output file
05112009,601,Excel,1_13020_DWS_1,1,999001
05112009,601,Excel,1_11020_SSGM_1,1,999001
05112009,601,Excel,1_13020_SSGM_1,1,999001
05112009,601,Excel,1_13020_SSGM_2,1,999001
05112009,601,Excel,1_13020_SSGM_3,1,999001
05112009,601,Excel,1_13020_SSGM_4,1,999001
05112009,601,Excel,1_13020_SSGM_5,1,999001
05112009,601,Excel,1_13020_SSGM_6,1,999001
05112009,601,Excel,1_13020_NEWE_1,1,999001
05112009,601,Excel,1_13020_NEWE_2,1,999001
05112009,601,Excel,1_13020_NEWE_3,1,999001
05112009,601,Excel,1_13020_NEWE_4,1,999001
05112009,601,Excel,1_13020_NEWE_5,1,999001
05112009,601,Excel,1_11020_NEWE_1,1,999001
05112009,601,Excel,1_11020_DWS_1,1,999001
05112009,601,Excel,1_11020_DWS_2,1,999001
05112009,601,Excel,1_11020_DWS_3,1,999001
05112009,601,Excel,1_11020_DWS_4,1,999001

Thanks in advance.

awk '{FS=OFS=",";$4=$4"_"++a[$4]}1' file

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.

Hi Danmero,

Thank you very much. It gives me exact result.

Regards,
gehlnar

Perl solution...

perl -e 'while(<STDIN>)  {  @a= split(/,/,$_); print "$a[0],$a[1],$a[2],$a[3]_" . ++$hash{$a[3]}. " ,$a[4],$a[5]"; }' < t

t is the input file..

Hi Geek,

Thanks for your input , this will help me if i use perl script.

Regards,
gehlnar