I am trying to sort and rename a large number of files that are labeled #####_##
The LEFT side of the underscore are numbers (e.g., 32956715, 32956810, etc.) that do not repeat.
The RIGHT side of the underscore are also numbers (e.g., 1, 2, 3, etc.) and they do repeat.
Example posted at pastebin
(The left side is the number of a scan and the right side is the page of that particular scan.)
I would like to be able to sort the left side of the underscore Z-A and the right side A-Z.
I'm open for any suggestions that achieve the result I'm looking for.
Currently I am using irfanview to send the filenames to a text file, then copying and pasting the text into excel, seperating the filenames into colums, then sorting the column with the LEFT side of the underscore by Z-A and the column with the RIGHT side of the underscore by A-Z. Then I essentially reverse the process and have irfanview thumbnail viewer load the files using a txt file created from my correctly sorted excel list.
There has to be a better way right?
More Information to attempt to clarify the question. I'm embarrased to admit this, but the end result is to print out each of these files and have them be face-up, in reverse chronological order (the newest document on top(face-up) and the oldest document on the bottom (face-up)). (Printing isn't very tech savvy is it? Can I still be in the superuser's club--please.)
A client gives us a disc of imaged documents (tiffs or gifs with jpgs mixed in). The discs can have anywhere from 50 to 20000 images on them. I have to print them out. Smaller numbers=older images and larger numbers=newer images. I am using Irfanview thumbnail viewer to batch print to a big copy machine. Right now I can only sort the images A-Z before printing while still keeping them in some recognizable order. Then I have to go through the printed stack and do the reverse chronological sorting myself. This is very time consuming and with attachments to documents it is difficult to determine where one document stops and the next begins.
I am not sure if I understood the question. If the left set of digits never repeat then the problem does not exist. You can not have a situation like 30000_1, 30000_2 because the left side does not repeat. – Sahil
You are correct. They do repeat if there is more than one page in the scanned document. I was just trying to differentiate that kind of repeating from the repeating on the right side which always starts with 1 and counts up based on the number of pages in the document.
I want to thank everyone who's already asked questions. It means you at least read the question and would try to help if I hadn't gone to great lengths to confuse you. I hope my extra info answers the other questions I did not address specifically.
The Lua script answer looks promising, but I am getting an error when trying to use it. Thoughts?
lua -e "io.stdout:setvbuf 'no'" "Reverse_Sort.lua" lua: Reverse_Sort.lua:16: attempt to compare number with nil stack traceback: Reverse_Sort.lua:16: in function <Reverse_Sort.lua:6> [C]: in function 'sort' Reverse_Sort.lua:32: in main chunk [C]: ? Exit code: 1