LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 10-20-2004, 01:35 PM   #1
jimmyj90
LQ Newbie
 
Registered: Oct 2004
Posts: 2

Rep: Reputation: 0
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
 
Old 10-20-2004, 01:42 PM   #2
Samsara
Member
 
Registered: May 2003
Distribution: Ubuntu, Mac OS X Tiger
Posts: 481

Rep: Reputation: 32
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" ...

Last edited by Samsara; 10-20-2004 at 01:43 PM.
 
Old 10-20-2004, 02:04 PM   #3
jimmyj90
LQ Newbie
 
Registered: Oct 2004
Posts: 2

Original Poster
Rep: Reputation: 0
thanks Samsara

I will look into it and post my results.

j
 
Old 10-20-2004, 05:06 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 12,157

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
To further define.
"1" "10" ..."2" "20" ... would be sorting alphanumerical
"1", "2", ... "10", "11" ... would be sorting numerical.
 
Old 10-20-2004, 06:18 PM   #5
Samsara
Member
 
Registered: May 2003
Distribution: Ubuntu, Mac OS X Tiger
Posts: 481

Rep: Reputation: 32
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting full directory listing sqn Programming 4 04-13-2005 05:33 PM
listing files in to an array sujith_deva Programming 1 12-12-2004 03:14 PM
Listing permissions with shell script Ollir Programming 1 10-18-2004 07:50 AM
listing files in a directory Linh Programming 7 05-17-2004 05:35 AM
listing files in apache im1crazyassmofo Linux - Software 0 07-27-2003 06:05 PM


All times are GMT -5. The time now is 03:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration