|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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" |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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] |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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}" |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|