The UNIX and Linux Forums  

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 here.

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 02:59 AM
last month end date vanathi UNIX for Advanced & Expert Users 7 03-21-2008 01:17 PM
How do I set my date in a unix script to 'new month Agent704 UNIX for Dummies Questions & Answers 1 01-27-2008 10:58 AM
Use date command to find last month Cbish68 Shell Programming and Scripting 5 08-10-2007 07:32 AM
find out month from a date rudoraj UNIX for Dummies Questions & Answers 5 07-03-2007 05:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-29-2005
Registered User
 

Join Date: Sep 2005
Posts: 130
how to get month last date in unix

Hello

I want to get end date of the any month in unix . is there any function to do this.


we can get month from date command 'date +%b'
example:

If Feb month then last date is 28

if sep then last date 30. like this


thanks

please help
Reply With Quote
Forum Sponsor
  #2  
Old 09-29-2005
Registered User
 

Join Date: Sep 2005
Location: Chennai,India
Posts: 12
Try this command
You can include this in a shell script to get the month and year to pass to the below command.

cal 10 05 | grep -v ^$ | tail -1 | sed 's/^.* \([0-9]*\)$/\1/'

Last edited by monsanbu; 09-29-2005 at 02:39 AM.
Reply With Quote
  #3  
Old 09-29-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
try this,

cal <month> <year> | sed '/^$/d' | tail -1 | awk '{printf $NF}'
Reply With Quote
  #4  
Old 09-29-2005
Registered User
 

Join Date: Sep 2005
Posts: 130
no use

not working

please check once again.

thanks
Reply With Quote
  #5  
Old 09-29-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Why dont you use the datecalc.

It does exactly what you require.
Reply With Quote
  #6  
Old 09-29-2005
Registered User
 

Join Date: Sep 2005
Location: Chennai,India
Posts: 12
Which solution is not working? Give the last two digits for year
Reply With Quote
  #7  
Old 09-29-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
echo $(cal 10 2005) | awk '{print $NF}'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0