LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   listing sequences of files to the shell (http://www.linuxquestions.org/questions/linux-newbie-8/listing-sequences-of-files-to-the-shell-245165/)

jimmyj90 10-20-2004 12:35 PM

listing sequences of files to the shell
 
I am wondering how to write a shell script that would list all of the files in a directory but if it is a part of a sequence list it as one.

EXAMPLE

/home/test/

file.1.txt
file.2.txt
file.3.txt
file2.1.txt
file2.2.txt
file2.3.txt
file2.4.txt
not_a_seq_file.txt


WOULD LIKE IT TO READ ->

/home/test/

file.1-3.txt
file2.1-4.txt
not_a_seq_file.txt

any one have any ideas on how i could do this?

thanks
j

Samsara 10-20-2004 12:42 PM

Try perl. I was actually thinking of writing something like this a while ago, but I'm not gonna get round to it, sorry!

Regards,

Samsara

PS: Okay, to get you started:
1) test if the file name contains a numerical character;
2) increment the numerical character and ask whether the file exists,
3) repeat until unsuccessful
4) voila

NB: note that some people count "00" "01" .... "10" "11" ...
whereas others count "1", "2", ... "10", "11" ...

jimmyj90 10-20-2004 01:04 PM

thanks Samsara

I will look into it and post my results.

j

michaelk 10-20-2004 04:06 PM

To further define.
"1" "10" ..."2" "20" ... would be sorting alphanumerical
"1", "2", ... "10", "11" ... would be sorting numerical.

Samsara 10-20-2004 05:18 PM

Quote:

Originally posted by michaelk
To further define.
"1" "10" ..."2" "20" ... would be sorting alphanumerical
"1", "2", ... "10", "11" ... would be sorting numerical.

Which is irrelevant to the solution I proposed, so long as the first digit of the varying position in the numerically smallest filename is not greater than the corresponding first digit of any subsequent file.

Regards,

Samsara


All times are GMT -5. The time now is 12:37 PM.