[NTLUG:Discuss] verify that a text string is a valid date.
Richard Geoffrion
ntlug at rain4us.net
Thu Feb 2 09:25:17 CST 2006
Richard Geoffrion wrote:
>Best viewed in fixed width font....obviously.
>
>
>
or...maybe NOT so obviously... let me try again. :)
<code>
#########################################################################
# Extract the date from the file and move pdf to the proper directory #
#########################################################################
#extract the date by cutting bytes 1-10 out of the filename
NEWDIRNAME=`echo $FILE | cut -b 1-10`
#########################################################################
# Verify that the date for NEWDIRNAME is a potentially valid one #
#########################################################################
#TODO: Convert $NEWDIRNAME to a julian date and back again and test
# for validity
#check the YearMonth delimiter and the MonthDay delimiter
YM=`echo $NEWDIRNAME | cut -b 5`
MD=`echo $NEWDIRNAME | cut -b 8`
#make sure that both YM and MD are dashes
if [ "$YM" = "-" -a "$MD" = "-" ] ; then
#Strip the filename of its date and the the IRFANVIEW's
#numbering scheme, then assign it to variable SFILE
#################################################################################
# echo $file to get the name, then cut out everything except for bytes 12 #
# and on.. then reverse what's left...then cut everything except for bytes 3 #
# and on (this gets rid of IRFANVIEW's anoying habit of numbering the scans #
# with 01 02 03..etc... and of course after you get rid of the scan number,you #
# have to re-reverse it so that it's back to normal. #
#################################################################################
SFILE=`echo $FILE | cut -b 12- | rev | cut -b 3- | rev`
#<snip the rest of what happens here>
else #assume the date format is bad and move the file into an unfiled folder
#make sure that the unfiled directory exist
if [ ! -d unfiled ] ; then
mkdir -p $UNFILED
chown $OWNER.$GRPOWNER $UNFILED
fi
# Set the StrippedFile name so that we remove the IRFANVIEW's numbering scheme
# but leave the invalid date.
SFILE=`echo $FILE | rev | cut -b 3- | rev `
#Set quotes around $SFILE because it hasn't been 'tr'ed to convert stupid
#spaces
mv $FILE.pdf "$UNFILED/$SFILE.pdf"
fi
</code>
There..that should fit..
More information about the Discuss
mailing list