I have filenames
filenameA_fg_MMDDYY.tar.gz
filenameASPQ_fg_MMDDYY.tar.gz
filenameAFTOPHYYINGH_fg_MMDDYY.tar.gz
filenameAGHYSW_fg_MMDDYY.tar.gz
My requiremnt needs to extract date which is in MMDDYYand change it into YYYYMMDD format.
I have done the following:
filedate=`echo $filename | awk -F"[_.]" '{print $(NF-2)}'`
formatdate = `echo $filedate | awk 'BEGIN {OFS=""}{print 20 substr($1,5,2), substr($1,1,2), substr($1,3,2)}'`
if [ formatdate -lt myowndate ]
This comparison doesnot work . I have tried putting quotes, < everything nothing works. I understand the problem is formatdate datetype is actually string and so it is not doing the compare.
Is there a way where I can change the MMDDYY date to YYYYMMDD number format . Basically what i need is the YYYYMMDD format to be number datatype . Any solution . I apologise if im not clear.:(:D:mad::o
I cannot use DATE command . I have to extract the date out of the filenames like
071609 and change it to 20090716. Change is not a problem but I need 20090716 in number format. Does it make sense?sorry again if im not clear. And thanks though
#!/bin/ksh
myowndate="$1"
shift
for fname in $*
do
# remove all before last _ including _
step1=${fname##*_}
# remove all after first . including .
mmddyy=${step1%%.*}
yyyymmdd="20${mmddyy:4:2}${mmddyy:0:2}${mmddyy:2:2}"
if (( yyyymmdd < myowndate )) ; then
echo "$fname"
fi
done
using ex.
./thisscript 20081130 filename*_*tar*
---------- Post updated at 10:41 AM ---------- Previous update was at 10:35 AM ----------
your "about" scriptlines include some syntax error.
No space using set value for variable:
formatdate=`echo ...
Using variable, need $
if [ "$formatdate" -lt "$myowndate" ] ; then
...
fi