Re: Sort files by filename



Les wrote:
On Tue, 2007-07-31 at 15:12 -0400, Mark Haney wrote:
Sort will give you the list. I don't know about sorting on a substring
with a command other than creating one. In C, you could read the
directory, then choose the substring using parsing, and finally look at
the last two characters prior to the period to get the sequence and look
for missing files. Do you know the first number and last number? If
not, then this won't work, because the first file and last file would
not have partners on each side to help you figure out if it was
missing.

The -k and -t options of sort may do what is needed. If you want to
sort starting with the 5 character of the name, you could probably
do something like sort -k 1.5 as long as there are no spaces in the
name. I believe something like -k 1.5,1.7 would use the 5th, 6th,
and 7th character. Now, if there is a field separator between parts
of the file name, you can use the -t option to use that to separate
the name into fields. This is handy when the names are not fixed
length. Something like 10-12-07_MKE_10.14_XX.jpg could be split
using _ as the field seperator, and sorting on the 4th field. You
may have to specify a numeric sort, especially if the numbers do not
have leading zeros.

sort -n -t _ -k 4

Mikkel
--

Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

Attachment: signature.asc
Description: OpenPGP digital signature

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list

Relevant Pages

  • Re: Sorting and then removing sort-by cols from a fixed-width flat file
    ... I will first merge them, then do the sorting, then remove the cols ... Does the "group by col" mean the column which contains the sort key? ... Sorting by character column numbers is generally not the easiest thing ...
    (comp.unix.programmer)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)
  • Re: Solution for sorting an array alpha-numerically
    ... strings up into groups and sorting the groups seperately, ... > so that numeric and alphabetic data sort as seperate groups. ... To the same project as the web page, add the class AlphaNumCompare() ...
    (microsoft.public.dotnet.general)
  • Re: how fast can I sort on mainframe (using DFSORT)?
    ... Since I joined the team as the performance lead a couple years ago, ... Frank now defers these types of questions to me. ... I have been out of the sorting business for a while, ... Writing to sort work files should not be the problem, ...
    (bit.listserv.ibm-main)
  • Re: except tasks from sorting
    ... position out of any sort key. ... But we will sorting subsequently. ... sort key is a Text ... hint to filtering the tasks before ...
    (microsoft.public.project)