Finding Files By Name

Finding Files - I am learning more about scripting each day but I am having a hard time figuring out how to write a script to pick particular files from a list ls command. Basically I have several hundred files with the file name being: AAB110321015704.raw or BBA110321015704.raw WHERE the numbers correspond with the date. In this example 11=2011 03=March 21=Day 21st HH=01 MM=57 SEC=04 I would like to write a script that will ask the user for the YYMMDD a start time and End time then it will find all the files based on the �file name� that are between that time. I have looked at using the -newer based on the actual file time written however the datetime is in central time and the file name is in zulu. It is this zulu time that I want represented in the file name. In my example if I was prompted and entered 110321 with a start time of 0100 and a end date of 110322 time of 0100 the 2 files above would be listed. Any recommendations how to do this?

Are all the candidate files in the same directory? Or are they scattered throughout a hierarchy?

Yes they are all in the same directory.

Try running this script in the directory containing the files:

#!/bin/bash
echo -n "Enter start date: "
read d
echo -n "Enter start time: "
read t
a="$d${t}00"
echo -n "Enter end date: "
read d
echo -n "Enter end time: "
read t
b="$d${t}00"
ls -l | awk -va=$a -vb=$b 'NR>1{x=$9;gsub("[^0-9]","",x);if (x>a&&x<b){print}}'

If you want just the file names:

#!/bin/bash
echo -n "Enter start date: "
read d
echo -n "Enter start time: "
read t
a="$d${t}00"
echo -n "Enter end date: "
read d
echo -n "Enter end time: "
read t
b="$d${t}00"
ls | awk -va=$a -vb=$b '{x=$0;gsub("[^0-9]","",x);if (x>a&&x<b){print}}'

Thanks I will try this.

#!/bin/sh

printf '%s' 'Begin searching at (enter timestamp in YYMMDDHHMMSS format): ' >&2
read ts1
printf '%s' 'Stop searching at (enter timestamp in YYMMDDHHMMSS format): ' >&2
read ts2

for f in *.raw; do
        ts=${f%.raw}
        ts=${ts##*[!0-9]}
        expr X$ts \>= X$ts1 \& X$ts \<= X$ts2 >/dev/null && printf '%s\n' "$f"
done

Prompts are written to stderr. Should you choose, you can redirect them to /dev/null, feed the timestamps from a file or a pipe, and use the script in a pipeline.

Not knowing which shell you're using, I chose to use the incredibly cumbersome expr utility. While its syntax clashes with the shell, requiring lots of quoting, it's widely available. Depending on your shell, it could possibly be replaced with test/[. The X's are there to force string comparison, since on some platform integers may not be large enough.

Assumption: The portion of the filename that precedes the timestamp never ends with a decimal digit.

Regards,
Alister

I will be using bash or ksh. Yes the portion of the filename that precedes never ends with a decimal. Thanks for your assistance. I am going to read and learn more about awk & expr