Since it is impossible to carry out the conversion into question in one run of the command :sort , consider it as a two-stage process.
The first step is to sort the rows by values ββseparated by commas in the column. To do this, we can use the command :sort , passing through the regular expression, which corresponds to the first column and the next separating comma. Since :sort compares text starting immediately after the specified pattern matches on each line, it gives us the desired sort order.
:sort/^[^,]*,/
To compare values, not lexicographically, use the n flag:
:sort n/^[^,]*,/
The second step involves executing the sorted rows and deleting all but one of those with the same value in the second column. it is convenient to build our implementation with the command :global , which executes the given Ex command in lines corresponding to a specific pattern. By definition, a row can be deleted if it contains the same value in the second column as the next row. This formalization (accompanied by an initial assumption that these commas cannot occur in column values) gives us the following pattern:
^[^,]*,\([^,]*\),.*\n[^,]*,\1,.*
So, if we run the command :delete on each row that satisfies this pattern, from top to bottom, we will only have one row for each individual value in the second column.
:g/^[^,]*,\([^,]*\),.*\n[^,]*,\1,.*/d_
Both of these steps can be combined into one Ex command,
:sort/^[^,]*,/|g/^[^,]*,\([^,]*\),.*\n[^,]*,\1,.*/d_