Specify Field To Sort By Using The Sort Command
The sort
command allows one to specify which field to sort by. These fields need to be separated by a character, such as a colon or comma, which is specified using the -t
option. To select the actual field to sort, specify the field position using the -k
option, which is one based:
$ cat eg.csv
111, plank, hello
222, apple, world
333, kilo, example
444, delta, values
$ sort -t, -k2 eg.csv
222, apple, world
444, delta, values
333, kilo, example
111, plank, hello