Unix - 过滤按文件名查找结果

时间:2015-04-03 16:39:21

标签: bash unix

在unix bash中,我得到的文件如下:

find . -regextype posix-egrep -iregex "./[0-9]{8}/exp/RESULT.out"| sort

./20150128/exp/RESULT.out
./20150210/exp/RESULT.out
./20150218/exp/RESULT.out
./20150224/exp/RESULT.out
./20150318/exp/RESULT.out
./20150327/exp/RESULT.out
./20150330/exp/RESULT.out

是否可以按日期YYYYMMDD日期字符串过滤此结果,以便我只获取指定日期之前的文件?

e.g。对于20150224,我只想得到

./20150128/exp/RESULT.out
./20150210/exp/RESULT.out
./20150218/exp/RESULT.out
./20150224/exp/RESULT.out

感谢您的帮助

2 个答案:

答案 0 :(得分:1)

通过

传递结果
awk -v FS=/ '$2<=20150224'

答案 1 :(得分:0)

您可以使用此find命令:

export s='20150224'

find . -regextype posix-egrep -iregex "./[0-9]{8}/exp/RESULT.out" -exec \
     bash -c 'IFS=/ read -ra arr <<< "$1"; ((${arr[1]} <= s)) && echo "$1"' - '{}' \;
./20150128/exp/RESULT.out
./20150210/exp/RESULT.out
./20150218/exp/RESULT.out
./20150224/exp/RESULT.out