Group lines by key.
$ groupby --help
Usage: groupby [OPTIONS]
Read lines from stdin and group lines by key.
-w, --width=N Use N chars as key[0].
-f, --fields=N Use N fields as key[1].
-s, --skip=N Skip N chars/fields[0].
-d, --delimiters=DELIM Use DELIM as field delimiter["\t "].
-j, --join-delimiter=DELIM Join lines by DELIM["\t"].
--help Display this help and exit.
$ cat input
1,2013,1,3000
2,2013,2,8800
3,2013,3,9500
4,2013,4,5700
5,2013,5,2600
6,2013,6,4100
7,2013,7,9900
8,2013,8,900
9,2013,9,7100
10,2013,10,8300
11,2013,11,7700
12,2013,12,1200
13,2014,1,8300
14,2014,2,3200
15,2014,3,7100
16,2014,4,3900
17,2014,5,4300
18,2014,6,7700
19,2014,7,9000
20,2014,8,2900
21,2014,9,8300
22,2014,10,6500
23,2014,11,1700
24,2014,12,3700
$ sort input |groupby -w1
1,2013,1,3000 10,2013,10,8300 11,2013,11,7700 12,2013,12,1200 13,2014,1,8300 14,2014,2,3200 15,2014,3,7100 16,2014,4,3900 17,2014,5,4300 18,2014,6,7700 19,2014,7,9000
2,2013,2,8800 20,2014,8,2900 21,2014,9,8300 22,2014,10,6500 23,2014,11,1700 24,2014,12,3700
3,2013,3,9500
4,2013,4,5700
5,2013,5,2600
6,2013,6,4100
7,2013,7,9900
8,2013,8,900
9,2013,9,7100
$ sort -t, -k2 input | groupby -d, -s1 -f1
1,2013,1,3000 10,2013,10,8300 11,2013,11,7700 12,2013,12,1200 2,2013,2,8800 3,2013,3,9500 4,2013,4,5700 5,2013,5,2600 6,2013,6,4100 7,2013,7,9900 8,2013,8,900 9,2013,9,7100
13,2014,1,8300 22,2014,10,6500 23,2014,11,1700 24,2014,12,3700 14,2014,2,3200 15,2014,3,7100 16,2014,4,3900 17,2014,5,4300 18,2014,6,7700 19,2014,7,9000 20,2014,8,2900 21,2014,9,8300
$ sort -t, -k3 input | groupby -d, -s2 -f1
1,2013,1,3000 13,2014,1,8300
22,2014,10,6500 10,2013,10,8300
23,2014,11,1700 11,2013,11,7700
12,2013,12,1200 24,2014,12,3700
14,2014,2,3200 2,2013,2,8800
15,2014,3,7100 3,2013,3,9500
16,2014,4,3900 4,2013,4,5700
5,2013,5,2600 17,2014,5,4300
6,2013,6,4100 18,2014,6,7700
19,2014,7,9000 7,2013,7,9900
20,2014,8,2900 8,2013,8,900
9,2013,9,7100 21,2014,9,8300
$ sort -t, -k4 -n input | groupby -d, -s3 -f1
8,2013,8,900
12,2013,12,1200
23,2014,11,1700
5,2013,5,2600
20,2014,8,2900
1,2013,1,3000
14,2014,2,3200
24,2014,12,3700
16,2014,4,3900
6,2013,6,4100
17,2014,5,4300
4,2013,4,5700
22,2014,10,6500
15,2014,3,7100 9,2013,9,7100
11,2013,11,7700 18,2014,6,7700
10,2013,10,8300 13,2014,1,8300 21,2014,9,8300
2,2013,2,8800
19,2014,7,9000
3,2013,3,9500
7,2013,7,9900