2

I have files with their names as

ABC_-_123321.20140505_-_161500.CSV
ABC_-_654145.20140506_-_135020.CSV
String_-_SerialID.Date_-_Time.CSV

StartDate, StartTime, EndDate and EndTime are given as input.

How can I get all filenames (or relative paths) having Date and Time between the given Date and Time ranges and write those to a Log file using a shell script?

Date and Time are not the last accessed or modified date/timestamp and there are no whitespaces in filenames.

And I can either take Date and Time input individually without any seperator between fields, for example
20140706
165030
or I can take input as
20140706165030

2
  • How the date and time relative?
    – cuonglm
    Jul 4, 2014 at 6:40
  • Date and Time together would corresponds to a Timestamp. Is that what u meant ? Jul 4, 2014 at 7:20

1 Answer 1

0

Algorithm to do this work:

for each file get the date & make difference the same with given date. Please find the below link for the date difference.

link

For solaris(unix without GNU date) use this link

If you want time wise , inside date for loop use loop for time . To get the difference in time you can use following code

      time1=14:30
      time2=$( date +%H:%M ) # 16:00
      diff=$(  echo "$time2 - $time1"  | sed 's%:%+(1/60)*%g' | bc -l )
      echo $diff hours
      # outputs 1.5 hours

Here sed replaces a : with a formula to convert to 1/60. Then the time calculation that is made by bc ( click link for more information).

Note : If the DIFFERENCE is +ve then , log/content can be put designated file otherwise not

1
  • Date difference that would do, but how can I retrieving filename and comparing parts of filename and then storing those filenames who satisfies the conditions into another file. Jul 8, 2014 at 4:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .