System = AIX
scripting = ksh
me = fairly new to this.
I hope this has not been asked already.
Scenario:
grep'ing for information out of files with a naming convention as such....
2008_01*. I will be performing my grep on these file names during the month after (i.e. 02).
Problem:
When I try to subtract "02" - "01", get "1". This makes sense seeing as how most calculations drop the preceding "0"
I need to keep that "0" to perform my grep.
Code:
# ======> GET YEAR & MONTH ***
#export YEAR=`date +%Y`
#export MNTH=`date +%m`
export YEAR=2008
export MNTH=02
# **************************************
# *** FIND PREVIOUS MONTH/YEAR VALUE ***
# **************************************
if [ $MNTH!=01 ]
then
(( MNTH=$MNTH-01 ))
YEAR=$YEAR
else
if [ $MNTH=01 ]
then
MNTH=12
(( YEAR=$YEAR-1 ))
fi
fi
***NOTE ~ (( YEAR=$YEAR-1 )) works perfectly.
!!!!!The above statement is now incorrect!!!!!
I would prefer to keep it as simple as it is now, however all help is appreciated. I would consider using
sed or awk to add the "0" in, however an example or two of how to do that would be great.