So can I calrify your requirements? For each numerical section on the file name, you want to sort ascending and then for each suffix you want to sort descending, as in from z to a? That doesn't match your output as far as I can see (although I haven't scrutinised it too closely.
Could you clearly paste (not just make up) some sample input and then manually work out the required output getting all the possibilities ironed out.
It might be possible with a single sort command specifying the numeric bit as a primary sort ascending and the suffix as a secondary descending if that's what you need.
Can you tell me the order that these files should process that you listed recently?
sn2015.12.14.12.29.25.log
sn2015.12.14.12.29.25_a.log
sn2015.12.14.12.29.25_b.log
sn2015.12.14.12.29.25_c.log
sn2015.12.14.12.30.23.log
sn2015.12.14.12.30.13_b.log
sn2015.12.14.12.30.24_a.log
sn2015.12.14.12.30.25_b.log
sn2015.12.15.12.30.23.log
sn2015.12.15.12.30.23_a.log
sn2015.12.15.12.30.24_b.log
It seems that these are sorted, but with the suffix being ascending as well (a to z) so it's just a simple sort without parameters.
sort file.txt
Indeed if this file file.txt
is built from the output from ls
in some way, I'm wondering why your output is not sorted already. Does this work:-
:
:
for file in fn*.log # Specify matching pattern, i.e. exclude .doc files
do
: # process $file
done
:
:
If there are too many files and the command fails for being too long, you could try:-
:
:
for file in `find . -name "fn*.log" | sort`
do
: # process $file
done
:
:
You need to be very clear about your need else we're just hoping that your "My car doesn't work" type description might be all sorts of serious things, or perhaps you are out of fuel.
We need accurate input to work on and meticulously checked required output to be certain we are going to be helpful and using our time well - we do all give it freely.
I do hope that we can still help you.
Robin