I want to distinct print the lines where diff is minimum. (diff=$2-$3)
The input file is:
c1,5,2 <-- diff=3
c1,5,3 <-- diff=2
c1,5,1 <-- diff=4
c2,8,3 <-- diff=5
c2,8,4 <-- diff=4
The expected output is:
c1,5,3
c2,8,4
How can I do this with Awk (e.g. with a one-liner)?
In other words, for each first field value (c1, c2), I want to print a single line with that first field value, chosen for the minimal diff between the second and third fields.