Hi All,
I have a file with data as below:
A,FILE1_MYFILE_20130309_1038,80,25.60
B,FILE1_MYFILE_20130309_1038,24290,18543.38
C,FILE1_dsc_dlk_MYFILE_20130309_1038,3,10.10
A,FILE2_MYFILE_20130310_1039,85,110.10
B,FILE2_MYFILE_20130310_1039,10,12.10
C,FILE2_err_dlk_MYFILE_20130310_1039,3,10.10
I am using following command to sum values of 3 column based on the value in second column.
for i in `cat OUTPUT_FILE|awk -F"," '{print $2}'|sort -u`;do grep $i OUTPUT_FILE|awk -F"," '{c+=$3}END{print $2".edr""|"c}';done
However the above command will definitely exclude third row as the value of second column in third row is not matching with that for other two rows. However, I want to include the third rwo as well. Hence I need to perform a pattern matching in the underlined part so that my output looks as below:
FILE1_MYFILE_20130309_1038,24373
FILE2_MYFILE_20130310_1039,98
How do I perform a pattern matching here.
Thanks and Regards
Angshuman