I've got a bunch of PDFs that I'm trying to append together, and I've got a program that, given a list of files, will append them to one PDF.
The issue I'm having is that piping the file names to sort does not produce the desired order. None of the flags of sort give me what I want either. I've got some examples below:
Desired sort order:
test1.pdf test2.pdf test10.pdf   Achieved sort order using sort:
test1.pdf test10.pdf test2.pdf   For more info on exactly what constitutes the sort order I desire, see:
http://msdn.microsoft.com/en-us/library/bb759947.aspx
In computing, natural sort order (or natural sorting) is the ordering of strings in alphabetical order, except that multi-digit numbers are treated atomically, i.e., as if they were a single character.
Sort a File Numerically To sort a file containing numeric data, use the -n flag with the command. By default, sort will arrange the data in ascending order. If you want to sort in descending order, reverse the arrangement using the -r option along with the -n flag in the command.
Bash Sort Files Alphabetically By default, the ls command lists files in ascending order. To reverse the sorting order, pass the -r flag to the ls -l command, like this: ls -lr . Passing the -r flag to the ls -l command applies to other examples in this tutorial.
In the Linux system, you will find one command named sort. This command can sort your data alphabetically. Here flag -k is used to select a field for sorting.
Assuming you're using GNU sort, use  the-V option:
   -V, --version-sort           natural sort of (version) numbers within text   For your input, it'd produce:
test1.pdf test2.pdf test10.pdf 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With