Confused with date - listing

Hello,:slight_smile:

Can anyone help me out in giving a script for my requirement please..

I have a number of files in a directory like
somenumber.0100
somenumber.0130
somenumber.0159
somenumber.0300
somenumber.0330
somenumber.0525
.
.
.

here, the number after the dot is the time (hhmm)
I need a script to list out all such files between 2 different times.

For example, This needs to satisfy different conditions like:
-files between 0100 and 0130 (mm of start < mm of end)
-files between 0100 and 0300 (hh of start > hh of end)
-files between 0100 and 0359 (mm of start < mm of end)
-files between 0159 and 0500 (mm of start > mm of end)

and also to pull a particular information/pattern from each of the listed files say if 50 files are listed get 50 patterns (one from each) but the pattern wud be similar... how to iterate over 50 files?

Your help is greatly appreciated Thanks..

how many 'conditions' will you have?
For the sample conditions:

-files between 0100 and 0130  (mm of start < mm of end)
ls *.01[1-3]*
-files between 0100 and 0300  (hh of start > hh of end)
ls *.0[1-3]*
-files between 0100 and 0359  (mm of start < mm of end)
ls *.0[1-3][0-5][0-9]
-files between 0159 and 0500  (mm of start > mm of end)

I mean to say all the different possibilities... if you give any start time to a particular end time the files between them should be listed out.

well in this case, you need to follow the filename globbing convention for each particular case like in the sample I've provided.

Another approach is to use parameter substitution to get the extensions of these files in a variable and compare:

#!/bin/ksh

for file in somenumber.*
do
        ext="${file##*.}"
done

You can use variable: ext value for comparison.

Sry if am not clear...

Need a script which takes the start time and end time as inputs. So, for any time interval the files in the directory somenumber.* shud be listed

Say for example I have the following files
*.0110
*.0115
*.0130
*.0145
*.0200
*.0215
*.0332
*.0358
*.0400
*.0430
*.0445
If I give 0100 to 0210 to my script as arguments result shud be
*.0110
*.0115
*.0130
*.0145
*.0200
Similarly if I give 0400 to 0500
*.0400
*.0430
*.0445

Just follow what Yoda's suggested - that should be easier to implement - give it a try.
Yoda, please let the OP try on his own first.

1 Like