The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-25-2008
cml2008 cml2008 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 12
need to keep the "0" in "01"

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.

Last edited by cml2008; 01-26-2008 at 12:15 AM.. Reason: statement is now incorrect