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


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux