The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help, I need to get the last date of previous month sirrtuan Shell Programming and Scripting 11 10-14-2008 05:59 AM
last month end date vanathi UNIX for Advanced & Expert Users 7 03-21-2008 04:17 PM
Use date command to find last month Cbish68 Shell Programming and Scripting 5 08-10-2007 10:32 AM
find out month from a date rudoraj UNIX for Dummies Questions & Answers 5 07-03-2007 08:21 AM
how to get month last date in unix rajan_ka1 Shell Programming and Scripting 12 10-04-2005 07:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-18-2006
devid devid is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 7
Formatting Date (adding a month)

i need to write a script that outputs a file with the following format used for its name BRHYYYYMM.TXT. I have no problems creating this file with the current year and month in the title but i would like the month to be the next period i.e. instead of BRH200601.TXT id like BRH200602.TXT. Im unable to pass parameters into the script as its a registered financials appliction script.

Currently have -

LOCFNAME="BRH`date '+%Y%m'.TXT"

How do i add 1 to the month? i also need to keep it as 2 digits

regards


dave
  #2 (permalink)  
Old 01-18-2006
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
something better than this should be there,

Code:
# !/usr/bin/ksh

m=`date +%m`
m=$(($m + 1))
if [ $m -lt 10 ]
then
m=0$m
fi

file="BRH`date +%Y`$m.TXT"
echo $file
exit 0

Last edited by matrixmadhan; 01-18-2006 at 09:47 AM..
  #3 (permalink)  
Old 01-18-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
matrixmadhan, what would happen if the month is Dec ?

Code:
#! /bin/ksh

typeset -Z2 M

M=$(date +%m)
Y=$(date +%Y)
if [ $M == 12 ] ; then 
        M=01
        Y=$(($Y+1))
else
        M=$(($M + 1))
fi;

file="BRH$Y$M.TXT"
echo $file
  #4 (permalink)  
Old 01-18-2006
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
i should have kept the sentinels in mind ... but didnt

good catch vino,

Code:
# !/usr/bin/ksh

m=`date +%m`
y=`date +%Y`
if [ $m -eq 12 ]
then
 y=$(($y + 1))
 m=0
fi
m=$(($m + 1))
if [ $m -lt 10 ]
then
m=0$m
fi

file="BRH$y$m.TXT"
echo $file
exit 0
  #5 (permalink)  
Old 01-18-2006
devid devid is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 7
Thanks for the sharp response chaps very much appreciated.

Regards

Dave
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0