Finding files within date range suffix

KrzyH

I have list of log files which names has date suffix:

mylog.2014-01-01.gz
mylog.2014-01-02.gz
........
mylog.2014-03-04.gz

I have a start and end date, for example 2014-02-01 -> 2014-02-04. Using bash on linux script I want to find files with name matching date range. So I want to get files:

mylog.2014-02-01
mylog.2014-02-02
mylog.2014-02-03
mylog.2014-02-04

I can not depend on

find /path -type f -newer $startFile -not -newer $endFile mylog*gz

because mylog.2014-02-01 can be modified on 2014-02-01 23:59 or 2014-02-02 00:01

PlasmaPower

Maybe:

START_DATE=$(date -d '2014-02-01 01' '+%s')
END_DATE=$(date -d '2014-02-04 01' '+%s')
IFS=.
for i in mylog.*.gz; do
    fname=($i)
    d=$(date -d "${fname[1]} 01" '+%s')
    if (($d > $START_DATE && $d < $END_DATE)); then
        echo "Found file: $i"
    fi
done

Thanks to @kojiro for the IFS and glob ideas.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bash - list files within date range

From Dev

Bash - list files within date range

From Dev

VBA-Excel Finding Finding two week date range and first account ID within this range

From Dev

Linux tar files within specific date range using filename date

From Dev

SQL query for finding all the records that exist on a particular date within some date range

From Dev

Finding records between date range

From Dev

Finding records between date range

From Dev

Finding a record based on range of date

From Dev

Finding vevents between date range

From Dev

Finding number of elements within a given range in an array

From Dev

Finding if a number falls within a certain range python

From Dev

Finding and deleting files with a specific date

From Dev

Count Distinct Within Date Range

From Dev

Find Date falls within Range

From Dev

Finding date range for week for particular month and year

From Dev

excel vba range.find not finding date

From Dev

Finding missing dates compared to date range

From Dev

Finding date range for week for particular month and year

From Dev

Finding Date Range from String Values in SPARQL

From Dev

Finding a file within recursive directory of zip files

From Dev

Finding the number of rows for all files within a folder

From Dev

Finding the number of rows for all files within a folder

From Dev

Renaming Files from finding a string within the file

From Dev

How to check if the date is within a specifed date range

From Dev

Copy files from one folder to another folder within specific date range

From Dev

Copy files from one folder to another folder within specific date range

From Dev

How can I count the number of specific files within a date range on the command line using bash?

From Dev

Count if date range fits within other date range

From Dev

Average a range of values if the date associated with it falls within a date range

Related Related

  1. 1

    Bash - list files within date range

  2. 2

    Bash - list files within date range

  3. 3

    VBA-Excel Finding Finding two week date range and first account ID within this range

  4. 4

    Linux tar files within specific date range using filename date

  5. 5

    SQL query for finding all the records that exist on a particular date within some date range

  6. 6

    Finding records between date range

  7. 7

    Finding records between date range

  8. 8

    Finding a record based on range of date

  9. 9

    Finding vevents between date range

  10. 10

    Finding number of elements within a given range in an array

  11. 11

    Finding if a number falls within a certain range python

  12. 12

    Finding and deleting files with a specific date

  13. 13

    Count Distinct Within Date Range

  14. 14

    Find Date falls within Range

  15. 15

    Finding date range for week for particular month and year

  16. 16

    excel vba range.find not finding date

  17. 17

    Finding missing dates compared to date range

  18. 18

    Finding date range for week for particular month and year

  19. 19

    Finding Date Range from String Values in SPARQL

  20. 20

    Finding a file within recursive directory of zip files

  21. 21

    Finding the number of rows for all files within a folder

  22. 22

    Finding the number of rows for all files within a folder

  23. 23

    Renaming Files from finding a string within the file

  24. 24

    How to check if the date is within a specifed date range

  25. 25

    Copy files from one folder to another folder within specific date range

  26. 26

    Copy files from one folder to another folder within specific date range

  27. 27

    How can I count the number of specific files within a date range on the command line using bash?

  28. 28

    Count if date range fits within other date range

  29. 29

    Average a range of values if the date associated with it falls within a date range

HotTag

Archive