casualfred's shell script approach is a clever one. You might need to adjust it a bit in case a file name with the exact date and time the user entered, doesn't exist. If you don't mind including an
awk program as part of the solution, and if I understood what you wanted, this appears to work do a comparison, whether or not a file exists with a name containing the exact date/time the User enters.
I put the list of file names you provided in a file named
data.txt and the following program in a file named
date_list.gawk:
Code:
( NR == 1 ) { start_date = $1 + 0 ; end_date = $2 + 0 ; }
# File name pattern: example20120826184847syslog.log
( NR > 1 ) { match( $0 , /([0-9]+)/ ) ; file_date = substr( $0 , RSTART , RLENGTH ) + 0 ; if ( ( file_date >= start_date ) && ( file_date <= end_date ) ) print $0 ; }
Then when I run this command sequence, to input a date range and the list of file names to the
awk program:
Code:
( echo 20120826184848 20120827153241 ; cat data.txt ) | gawk -f date_list.gawk
I get this output:
Code:
example20120826184848syslog.log
example20120826185226syslog.log
example20120826193642syslog.log
example20120827153241syslog.log
Hope this helps.