Re: Sort files by filename



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

Relevant Pages

  • Re: How to make Forth interesting?
    ... Shell utilities: ... to do a table indexed with the words: wordlists. ... I guess that there are also systems that include a sort, ... sorting with counted uniqueness is good enough. ...
    (comp.lang.forth)
  • Re: sort + head = weirdness?
    ... >'sort'and then through 'head' and I'm getting really strange results. ... >works fine with 'sort' itself. ... buffer, so there's no attempt to write anything after "head" has exited. ... Check the documentation of the shell (you didn't say what shell you're ...
    (comp.unix.shell)
  • Re: Which countries contribute most to the total?
    ... If you're going to use UNIX sort and forget about skipping the header ... or various other options that just has shell call awk rather than ...
    (comp.lang.awk)
  • Re: hc11 program help
    ... >saw reference to it for the first time in a Byte magazine article. ... one should say Shell sort. ... >bubble sort with similar technique applied, it's a comb sort. ...
    (comp.arch.embedded)
  • Re: how do i change the default sort of the media player
    ... Sort order in the shell doesn't matter at all. ... then right click and select play. ...
    (microsoft.public.windowsmedia.player)