Bash list files with range

柔情痞子 提交于 2019-12-04 22:37:06

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"

You can utilize printf facility in that case.

Consider this script:

for i in {1..2}; do for j in {01..12}; do printf "%02d%02d\n" $i $j; done; done

**UPDATE: For using variable:

start=1
end=2
for ((i=start; i<=end; i++)); do
   for ((j=1; j<=12; j++)); do printf "%02d%02d\n" $i $j; done
done

0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!