Thursday, February 28, 2013

List files within date range

Problem: List files from january 26 to february 25


Files:


asterlui@192.168.1.1:/usr/src/test$ ls -l
total 0
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130126
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130127
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130225
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130227


command: ls log_* | awk -F \_ -v start=20130126 -v end=20130225 '{d=substr($1,9); if (d>=start&&d<=end) print}'


asterlui@192.168.1.1:/usr/src/test$ ls log_* | awk -F \_ -v start=20130126 -v end=20130225 '{d=substr($0,9); if (d>=start&&d<=end) print}'
log_20130126
log_20130127
log_20130225

No comments:

Post a Comment