bash sort quoted csv files by numeric key

bash, csv, sorting

Solution

A little trick, which uses a double quote as the separator:

sort --field-separator='"' --key=4 -n

Problem

I have the following input csv file: ``` "aaa","1","xxx" "ccc, Inc.","6100","yyy" "bbb","609","zzz" ``` I wish to sort by the second column as numbers, I tried ``` sort --field-separator=',' --key=2n ``` the problem is that since all values are quoted, they don't get sorted correctly by -n (numeric) option. is there a solution?

Original source