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

1 Answers1

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

  • 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. – FredOscatore Jul 08 '14 at 04:34