Loading...

Finding files within date range suffix

Answer #1 100 %

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.

Tags: bashdate

You’ll also like:


© 2023 CodeForDev.com -