Re: Sort files by filename

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

 



Les Mikesell wrote:
> Mark Haney wrote:
>>> count=xx
>>> for i in $(ls <something>* | sort) ; do
>                         ^^^^^^^^^^^^
> The |sort isn't necessary since the shell always returns wild-card
> expansions in sorted order.  In fact the ls isn't necessary either since
> the shell has already generated the list.

You are correct, it is not be necessary in the example - I put it in
as an option if you were not sorting on the entire file name, but on
a specific field. You have more options on how you sort by piping
the list though sort. In this case, the -k or -M options may be handy.

>   for i in something*
> will do the same thing.
> 
>>>     file_num=$(cut --delimiter=_ -f1 $i)
>>>     while [ $count -lt $file_num ] ; do
>>>         echo Missing file number $count           count++
>>>     done
>>> done
>>>
> 
>> This is great. I think now I have enough pieces to make something
>> work. I appreciate all the help.
> 
> The above doesn't help if you lose the 1st or last bunch of files.  Do
> you always get the same set every day?
> 
It will catch if the first file is missing - the first entry will be
greater then count. If you know in advance how many files there
should be, you could add a test to see if the last file is
xx+number, as well as using that as an exit for the while loop.

As I had stated in the comments after the script, it was not
intended as a finished solution, but as a starting point for
building something that fit data better.

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