Sorry for the delay, it has been an unexpectedly busy end of the week.
Quote:
Originally Posted by
Don Cragun
The goal of The UNIX and Linux Forums is to help you learn how to do "stuff" on your own; not to write programs for you.
I completely understand and agree with this. I always try to start with a post that contains at least some kind of a working script. This is to do as much as I can on my own and let the other users here know that I am working to solve the problem, not expecting others to do it for me. I also think that compared to a text explanation, programming code is easier to read in terms of understand what a person is after. I read long prose explanations of code algorithms when I am having trouble falling asleep at night. I still haven't consistently found the sweet spot when it comes to exactly how much to post. It appears that my first attempt was to short to explain all I was trying to do, and my second was way too long to bother wading into.
It turns out that I didn't end up using an array. Everything that came out of the code you posted ended up in a single long string variable ($FILE_LIST). I just looped on the number of files I was expecting to find and parsed the long string to pull out the file name for each iteration of the loop.
Quote:
Originally Posted by
Don Cragun
But, why have an array at all. Why not just process the files one at a time as they come out of awk?
The simple explanation for this is that I don't know awk very well at all. I can more or less use it to parse things, but only in the simplest implementations. I did spend some time trying to take the output from awk and work with it, but I think I was using a redirect instead of a pipe.
So as I read this now, ls is passing all .out.txt to sort, sort is sorting on the key field and passes the sorted list to awk. Awk processes each item in the list and outputs the specified fields. Then it looks like the output of awk is passed to read, which dumps the output into the vars $FILE_NAME and $RAND_SET. Once you are there, the rest is straightforward. I am not familiar with read, so that is something new to me. I would not have known how to get awk to output two variables and get them into something that I could use with cp. I am also not quite clear about how awk knows when it has read in enough lines to get to $FILE_COUNT. Is "NR" an implicit running counter of some kind so that when NR > $FILE_COUNT awk quits (I see that you have passed $FILE_COUNT to awk as c)?
From time to time I think I am getting better at this, then I try to do something new and find out how much I still don't know. I do really appreciate that help that is available here.
LMHmedchem