My script has to list all files between a given range of date within a file name (ex: 20130133.212001.log). The start date and end date will be given by user. I now have start_year, end_year, start_month, end_month....so on till end_second. My plan was to use ls syntax:
ls *{start_year..end_year}{start_month..end_month}{.....}.log
But the problem is if month or date has 01 bash is taking it as 1. Indeed my bash version is older than 4. I can't considering updating the bash version. Any other method that I use to list files in such range.
[EDIT]
$> cat tmp.sh
#! /bin/bash
start_year=2013
end_year=2013
start_month=01
end_month=01
start_date=01
end_date=12
start_month=$(printf %02d $start_month)
end_month=$(printf %02d $end_month)
start_date=$(printf %02d $start_date)
end_date=$(printf %02d $end_date)
ls {$start_year..$end_year}{$start_month..$end_month}{$start_date..$end_date}.log
$>
but output is:
$>./tmp.sh
ls: {2013..2013}{01..01}{01..12}.log: No such file or directory
while the current dir contains:
$> ls
20130101.log 20130103.log 20130105.log 20130107.log 20130109.log 20130111.log 20130201.log abcd.log
20130102.log 20130104.log 20130106.log 20130108.log 20130110.log 20130112.log 2013.log tmp.sh
$>
How about like this:
start=$start_year$(printf %02d $start_month)
end=$end_year$(printf %02d $end_month)
ls *.log | sed -ne "/$start/,/$end/p"