Sorting

I do sort on the date and Time chronologically, how can I make the NIL to be below in the output

Input file:

KT NIL NIL
ZK 02/09/2016 18:11
CD NIL NIL
AS 02/09/2016 18:22
AB 02/08/2016 18:17
VA 02/09/2016 18:50
CX 02/09/2016 18:10 
  
sort -b -k 2.9,2.10 -k 2.1,2.2 -k 2.4,2.5 -k 3,3 file
KT NIL NIL
CD NIL NIL 
AB 02/08/2016 18:17
CX 02/09/2016 18:10
ZK 02/09/2016 18:11
AS 02/09/2016 18:22
VA 02/09/2016 18:50

Desired output:

AB 02/08/2016 18:17
CX 02/09/2016 18:10
ZK 02/09/2016 18:11
AS 02/09/2016 18:22
VA 02/09/2016 18:50
KT NIL NIL
CD NIL NIL

Try

LC_ALL=C sort -k 2.6,2.10 -k 2.1,2.2 -k 2.4,2.5 -k 3,3 file

(It fixes a Y3000 problem, and by chance fixes your problem.)

Thank You. I just a found a way out, by piping to awk

sort -b -k 2.9,2.10 -k 2.1,2.2 -k 2.4,2.5 -k 3,3 file | awk '$2~/NIL/{A[NR]=$0;next}{print}END{for (i in A){print A}}

MadeInGermany is right: You need to sort on the entire year; not just the last two digits. But, it isn't a year 3000 problem, it is a year 2100 problem.

Also note that there is no need to sort the month and day separately. So, you should probably change the sort command in your pipeline to:

LC_ALL=C sort -k 2.6,2.10 -k 2.1,2.5 -k 3,3 file

The following would also work, but I prefer to keep the sort keys distinct to avoid confusion for someone trying to read your code later:

LC_ALL=C sort -k 2.6,2.10 -k 2,2 -k 3,3 file