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
YYYYMMMDDin the 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,6 DY,YES,MAYBE,\PathDY/subj/defn/some-file-name-20140720.txt,6
I 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.
AX,NO,NO,\PathAX/subj/categ/some-file-name-20151229.txt, CXX,YES,YES,\Path/subj/categ/some-file-20140503.txt,6 CXX,NO,NO,\PathCXX/subj/categ/some-file-name-20151229.txt, DY,YES,MAYBE,\PathDY/subj/categ/some-file-name-20140720.txt,6
I case it helps:
YYYYMMDDfollows the last dash in the file name and before the file extension.
- The dash prior to
YYYYMMDDis 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.
- MacOS 10.9.5