If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help needed in Unix Shell Script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-04, 06:05
arunprasadlv arunprasadlv is offline
Registered User
 
Join Date: Mar 2004
Location: India
Posts: 41
Help needed in Unix Shell Script

Hi Everbody,

I wanna write which shuld take the date as input say 02-06-04 and display the output as 02-JUN-2004.


Thanks and Regards,
Arun
Reply With Quote
  #2 (permalink)  
Old 09-07-04, 06:56
SiverSloth SiverSloth is offline
Registered User
 
Join Date: Jun 2004
Posts: 29
The brute force method

Code:
#!/bin/ksh

DAY=`echo $1 | cut -f 1 -d '-'`
MONTH=`echo $1 | cut -f2 -d '-'`
YEAR=`echo $1 | cut -f3 -d '-'`

case $MONTH in

  01) echo ${DAY}-JAN-$YEAR;;
  02) echo ${DAY}-FEB-$YEAR;;
  03) echo ${DAY}-MAR-$YEAR;;
  04) echo ${DAY}-APR-$YEAR;;
  05) echo ${DAY}-MAY-$YEAR;;
  06) echo ${DAY}-JUN-$YEAR;;
  07) echo ${DAY}-JUL-$YEAR;;
  08) echo ${DAY}-AUG-$YEAR;;
  09) echo ${DAY}-SEP-$YEAR;;
  10) echo ${DAY}-OCT-$YEAR;;
  11) echo ${DAY}-NOV-$YEAR;;
  12) echo ${DAY}-DEC-$YEAR;;
esac
Note that there is no parameter vetting at all.
Reply With Quote
  #3 (permalink)  
Old 10-01-04, 11:57
sjumma sjumma is offline
Registered User
 
Join Date: Oct 2003
Posts: 232
can this be chanaged to ---

can this be changed to run in such a way that

at 2 am it gets the system date (month and day)

122(jan23rd) and join with a batch file myfile 122 (on windows 2000)

and for oct should be A22, noV should be B22 AND

DEC Should be C22

real catch is on 1st feb should be 131(jan 31st)

THANKS
__________________
bigfoots

Last edited by sjumma; 10-01-04 at 12:21.
Reply With Quote
  #4 (permalink)  
Old 10-27-04, 15:17
sjumma sjumma is offline
Registered User
 
Join Date: Oct 2003
Posts: 232
Arrow Their is always a way out but one problem

Here is how you can get it !!!!!!!!!!!!!!!!!!
One problem how do i log in( from window) from a batch file , run the script and get the output of this from a file e.g ver.bat
which i will run on dos ????


#!/usr/bin/ksh
TODAY=`date +'%m-%d-%Y'`

# Get individual elements
MONTH=`echo $TODAY | cut -d'-' -f1`
DAY=`echo $TODAY | cut -d'-' -f2`
YEAR=`echo $TODAY | cut -d'-' -f3`

if [[ `expr $DAY + 0` -eq 1 ]]; then
if [[ $MONTH -eq 1 ]]; then
MONTH=12
YEAR=`expr $YEAR - 1`
else
MONTH=`expr $MONTH - 1`
fi

cal $MONTH $YEAR | grep 31 1>/dev/null 2>&1
if [[ $? -eq 0 ]]; then
DAY=31
else
DAY=30
fi
else
DAY=`expr $DAY + 0`
DAY=`expr $DAY - 1`
fi

if [[ `echo $MONTH | wc -c` -eq 2 ]]; then
MONTH=0$MONTH
fi
if [[ `echo $DAY | wc -c` -eq 2 ]]; then
DAY=0$DAY
fi
# Previous day in the same format, without hyphens
# NEW_DATE=$MONTH$DAY
if [[ $MONTH -eq 10 ]]; then
MONTH=A
elif [[ $MONTH -eq 11 ]]; then
MONTH=B
elif [[ $MONTH -eq 12 ]]; then
MONTH=C
else MONTH=$MONTH
fi
filename=vercopy1
NEW_DATE="$filename $MONTH$DAY"

echo $NEW_DATE >ver.bat
__________________
bigfoots
Reply With Quote
  #5 (permalink)  
Old 10-27-04, 15:19
sjumma sjumma is offline
Registered User
 
Join Date: Oct 2003
Posts: 232
Arrow Their is always a way out but one problem

Here is how you can get it !!!!!!!!!!!!!!!!!!
One problem how do i log in( from window) from a batch file , run the script and get the output of this from a file e.g ver.bat
which i will run on dos ????
i did write a batch file

telnet servername
username
password
./verscirpt
open ftp servername
get ver.bat
exit
bye

It does not take username and password


#!/usr/bin/ksh
TODAY=`date +'%m-%d-%Y'`

# Get individual elements
MONTH=`echo $TODAY | cut -d'-' -f1`
DAY=`echo $TODAY | cut -d'-' -f2`
YEAR=`echo $TODAY | cut -d'-' -f3`

if [[ `expr $DAY + 0` -eq 1 ]]; then
if [[ $MONTH -eq 1 ]]; then
MONTH=12
YEAR=`expr $YEAR - 1`
else
MONTH=`expr $MONTH - 1`
fi

cal $MONTH $YEAR | grep 31 1>/dev/null 2>&1
if [[ $? -eq 0 ]]; then
DAY=31
else
DAY=30
fi
else
DAY=`expr $DAY + 0`
DAY=`expr $DAY - 1`
fi

if [[ `echo $MONTH | wc -c` -eq 2 ]]; then
MONTH=0$MONTH
fi
if [[ `echo $DAY | wc -c` -eq 2 ]]; then
DAY=0$DAY
fi
# Previous day in the same format, without hyphens
# NEW_DATE=$MONTH$DAY
if [[ $MONTH -eq 10 ]]; then
MONTH=A
elif [[ $MONTH -eq 11 ]]; then
MONTH=B
elif [[ $MONTH -eq 12 ]]; then
MONTH=C
else MONTH=$MONTH
fi
filename=vercopy1
NEW_DATE="$filename $MONTH$DAY"

echo $NEW_DATE >ver.bat
__________________
bigfoots
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On