Enjoy **_awk_** solution:
awk -F, '{ diff=$2-$3; if(a[$1]>diff || !a[$1]) { a[$1]=diff; b[$1]=$2 FS $3 } }
END{ for(i in a) print i,b[i] }' OFS=',' yourfile
The output:
c1,5,3
c2,8,4
Enjoy **_awk_** solution:
awk -F, '{ diff=$2-$3; if(a[$1]>diff || !a[$1]) { a[$1]=diff; b[$1]=$2 FS $3 } }
END{ for(i in a) print i,b[i] }' OFS=',' yourfile
The output:
c1,5,3
c2,8,4