Re: Sort files by filename

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux