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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare 2 files and output result in pop up window hongsh UNIX for Dummies Questions & Answers 2 05-23-2008 10:50 AM
awk to output cmd result IMTheNachoMan HP-UX 4 04-27-2008 10:41 AM
Need to Output result to a non-delimitted file cosec Shell Programming and Scripting 1 04-07-2008 05:51 AM
Outputting formatted Result log file from old 30000 lines result log<help required> vikas.iet Shell Programming and Scripting 5 12-02-2007 10:43 PM
any possible to run sql result and output to file happyv Shell Programming and Scripting 7 03-02-2007 01:07 PM

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 05-18-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
output result (period -1)

hello,

I have the following basic script which input the period, but I would like to output is period -1.. how?

echo Please input period (yyyymm):
read PERIOD
OUTPUT=$PERIOD -1
echo " you request period -1 is $OUT"

input 200705
output 200704
input 200701
output 200612

The above script is not work.

Please advise.

Thx!
  #2 (permalink)  
Old 05-18-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,423
Search this forum, this problem has been answered many times.

Read this thread Getting yesterday DATE

Read this FAQ Yesterdays Date/Date Arithmetic

Read this TIP Simple date and time calulation in BASH

Jean-Pierre.
  #3 (permalink)  
Old 05-18-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try...
Code:
echo "200701"|awk '{y=substr($0,1,4);m=substr($0,5,2)-1;if(m==0){m=12;y--};printf "%04d%02d\n",y,m}'
  #4 (permalink)  
Old 05-18-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
Quote:
Originally Posted by anbu23
Code:
echo "Please input period (yyyymm):"
read PERIOD
OUTPUT=`expr $PERIOD - 1`
echo " you request period -1 is $OUTPUT"
Thx! it work now.

what is the meaning of "expr"?
  #5 (permalink)  
Old 05-18-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by happyv
Thx! it work now.

what is the meaning of "expr"?
expr is a command which evaluate expressions.
I didn't read your requirement properly. My solution wont work for all the situations. Try Ygor's solution.
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 03:53 PM.


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