PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > How to get the Previous month in Korn Shell
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

How to get the Previous month in Korn Shell

Réponse
 
LinkBack Outils de la discussion
Vieux 19/03/2008, 04h23   #1
narendra vuradi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to get the Previous month in Korn Shell

Hi I have a requirement where i have to append the prev month (e.g Feb
for current date ) to the file name before sending it for some other
processing.

if input file name is
xyz.txt output for the today's run should be xyz_Feb.txt.

i tried this code
1 curmth=`date +%m`
2 mth=(Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
3 prevmth=${mth[$((curmth - 1))]}
4 echo $prevmth

but its giving a syntax error at Line 2 : `(' unexpected.

TIA.

Regards,
naren
  Réponse avec citation
Vieux 19/03/2008, 04h49   #2
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get the Previous month in Korn Shell

narendra vuradi wrote:
> Hi I have a requirement where i have to append the prev month (e.g Feb
> for current date ) to the file name before sending it for some other
> processing.
>
> if input file name is
> xyz.txt output for the today's run should be xyz_Feb.txt.


$ date '+%b'
Mar
$ date -d 'last month' '+%b'
Feb



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
  Réponse avec citation
Vieux 19/03/2008, 05h14   #3
narendra vuradi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get the Previous month in Korn Shell

On Mar 19, 8:49 am, "John W. Krahn" <some...@example.com> wrote:
> narendra vuradi wrote:
> > Hi I have a requirement where i have to append the prev month (e.g Feb
> > for current date ) to the file name before sending it for some other
> > processing.

>
> > if input file name is
> > xyz.txt output for the today's run should be xyz_Feb.txt.

>
> $ date '+%b'
> Mar
> $ date -d 'last month' '+%b'
> Feb
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall



Hi when i ran this code i am getting the following error
"getmonth.ksh[9]: $: not found"

  Réponse avec citation
Vieux 19/03/2008, 05h17   #4
narendra vuradi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get the Previous month in Korn Shell

On Mar 19, 8:49 am, "John W. Krahn" <some...@example.com> wrote:
> narendra vuradi wrote:
> > Hi I have a requirement where i have to append the prev month (e.g Feb
> > for current date ) to the file name before sending it for some other
> > processing.

>
> > if input file name is
> > xyz.txt output for the today's run should be xyz_Feb.txt.

>
> $ date '+%b'
> Mar
> $ date -d 'last month' '+%b'
> Feb
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall


hi when i ran the above code i am getting the following error
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
  Réponse avec citation
Vieux 19/03/2008, 05h53   #5
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get the Previous month in Korn Shell

On 2008-03-19, narendra vuradi wrote:
> Hi I have a requirement where i have to append the prev month (e.g Feb
> for current date ) to the file name before sending it for some other
> processing.


If you have the GNU version of date:

date -d 'last month' +%b

Or try the date arithmetic section of the FAQ:
<http://cfaj.freeshell.org/shell/cus-faq.html#6>

Also, Chapter 8 of my book, which is online at
<http://cfaj.freeshell.org/shell/ssr/08-The-Dating-Game.shtml>

> if input file name is
> xyz.txt output for the today's run should be xyz_Feb.txt.
>
> i tried this code
> 1 curmth=`date +%m`
> 2 mth=(Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
> 3 prevmth=${mth[$((curmth - 1))]}
> 4 echo $prevmth
>
> but its giving a syntax error at Line 2 : `(' unexpected.


The shell you are using doesn't have arrays (they are not
standard).

curmth=`date +%b`
mth=DecNovOctSepAugJulJunMayAprMarFebJanDec
tmp=${mth#*$curmth}
prevmth=${tmp%${tmp#???}}

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 19/03/2008, 07h42   #6
Rakesh Sharma
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get the Previous month in Korn Shell

On Mar 19, 8:23 am, narendra vuradi <nvur...@gmail.com> wrote:
> Hi I have a requirement where i have to append the prev month (e.g Feb
> for current date ) to the file name before sending it for some other
> processing.
>
> if input file name is
> xyz.txt output for the today's run should be xyz_Feb.txt.
>
> i tried this code
> 1 curmth=`date +%m`
> 2 mth=(Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
> 3 prevmth=${mth[$((curmth - 1))]}
> 4 echo $prevmth
>
> but its giving a syntax error at Line 2 : `(' unexpected.
>
> TIA.
>
> Regards,
> naren




set 'Dec' 'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct'
'Nov'
set x `expr \`date '+%m'\` + 1` ${1+"$@"}; shift
eval "prevmth=\${$1}"
  Réponse avec citation
Vieux 19/03/2008, 09h03   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get the Previous month in Korn Shell

2008-03-18, 20:23(-07), narendra vuradi:
> Hi I have a requirement where i have to append the prev month (e.g Feb
> for current date ) to the file name before sending it for some other
> processing.
>
> if input file name is
> xyz.txt output for the today's run should be xyz_Feb.txt.
>
> i tried this code
> 1 curmth=`date +%m`
> 2 mth=(Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
> 3 prevmth=${mth[$((curmth - 1))]}
> 4 echo $prevmth
>
> but its giving a syntax error at Line 2 : `(' unexpected.

[...]

IFS=';'
set -f
set -- $(locale abmon)
set x "${12}" "$@"
now=$(date +%m)
shift "${now#0}"
lastmonth=$1


--
Stéphane
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h11.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,29006 seconds with 15 queries