I want to sort the file based on the text before the first comma, but also want a second level sort based on the date YYYYMMMDD in the sample input:Sample Input:AX,NO,NO,\PathAX/subj/defn/some-file-name-20151229.txt,CXX,NO,NO,\PathCXX/subj/defn/some-file-name-20151229.txt,CXX,YES,YES,\Path/subj/defn/some-file-20140503.txt,6DY,YES,MAYBE,\PathDY/subj/defn/some-file-name-20140720.txt,6I can solve the first part with sort -t, -k1,1, but don't know how to daily do the second part as the number of dashes in the file name is not fixed. Thus I can't just specify the column number with a - as a separator.Desired output:AX,NO,NO,\PathAX/subj/categ/some-file-name-20151229.txt,CXX,YES,YES,\Path/subj/categ/some-file-20140503.txt,6CXX,NO,NO,\PathCXX/subj/categ/some-file-name-20151229.txt,DY,YES,MAYBE,\PathDY/subj/categ/some-file-name-20140720.txt,6Notes:I case it helps:The YYYYMMDD follows the last dash in the file name and before the file extension.The dash prior to YYYYMMDD is always present, thus at least one dash.There are no other dots in the file, except for the file extension.I can think of a two pass process where the last - is replaced by some other character that will not appear in the file, and then sort and replace the character back with a dash, but wondering if there is an easier way.Platform:MacOS 10.9.5
Sorting based on last occurrence of character
sort