display number of days in current month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting display number of days in current month
# 8  
Old 03-15-2011
wow thanks guys
# 9  
Old 03-15-2011
hehehe, so many ways to skin a cat.

@ctsgnb, thanks was my sed solution - fix was pretty simple:
Code:
# cal 7 2011 | sed -n '/[23]/h;${x;s/.* //;p}'
31

# 10  
Old 03-15-2011
Hehe yes,

@Schubler,

Your fix works on linux... but it requires an additional little semicolon fix to work on the solaris 10 i have tryied (i think FreeBSD has the same kind of need of ending semicolon before "}" ... so in fact better to keep both of the semicolon before and after the p

Code:
$ uname -a
SunOS xxxxxx 5.10 Generic_141414-01 sun4u sparc SUNW,Sun-Fire-V490
$ cal 7 2011 | sed -n '/[23]/h;${x;s/.* //;p}'
sed: command garbled: /[23]/h;${x;s/.* //;p}
$ cal 7 2011 | sed -n '/[23]/h;${x;s/.* //;p;}'
31
$

another one for the fun ...
Code:
$ echo $(cal) | tail -c 3
31

or if running solaris
Code:
$ echo $(cal) | /usr/xpg4/bin/tail -c 3
31


Last edited by ctsgnb; 03-15-2011 at 09:36 PM..
# 11  
Old 03-15-2011
Using FreeBSD Man Page for date (FreeBSD Section 0) - The UNIX and Linux Forums
Code:
# uname
FreeBSD
# date
Tue Mar 15 21:05:40 EDT 2011
# date -v 1d -v +1m  -v -1d "+%A %B %d %Y"                           # First day of (current month+1) minus 1 day.
Thursday March 31 2011
# date -v 1d -v +1m  -v -1d "+%d"
31

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Subtracting number of days from current date

Hi All, I am using KSH shell and need to subtract n number of days from the current date .. kindly suggest ! Thanks in advance!:) (20 Replies)
Discussion started by: dev.devil.1983
20 Replies

2. Shell Programming and Scripting

Number of days in current month

I have a homework assignment: ---------------------------------------- "Display" the number of days in the current month. For example: September 1996 has 30 days ---------------------------------------- I am trying to just display the head of cal to start the sentence. eg. cal | head ... (1 Reply)
Discussion started by: eaafuddy
1 Replies

3. Shell Programming and Scripting

How to Find number of days in a month in mmddyyyy format?

Hi Guru's, I am working on a shell script from past a month and unable to get rid of automating while working with dates,here's what i have. inital_date=11012011 final_date=11302011 expected_output= has to be in below format PFB 11012011 11022011 11032011 * * * 11102011 * *... (9 Replies)
Discussion started by: Gaurav198
9 Replies

4. Programming

Number of days in month from certain parameters, c programming request.

Hi, I have an issue in date processing, the issue is I have a month as an int ( 1 - 12 ), the weekday as int ( 0 - 6 , 0 = Sunday), and the week day in month as int ( 0 - 5, 5 = last ex: first sunday, last monday, third tuesday ... ), now from those three parameters is there a possible way to... (2 Replies)
Discussion started by: modn3
2 Replies

5. Shell Programming and Scripting

Number of days in month from certain parameters

Hi, I have an issue in date processing, the issue is I have a month as an int ( 1 - 12 ), the weekday as int ( 0 - 6 , 0 = Sunday), and the week day in month as int ( 0 - 5, 5 = last ex: first sunday, last monday, third tuesday ... ), now from those three parameters is there a possible way to... (5 Replies)
Discussion started by: modn3
5 Replies

6. Shell Programming and Scripting

Number of days in the previous month

Hi all. I am scripting in a POSIX shell on HPUX. I am running a script that needs to determine the number of days in a month. I found this on the forum and it works great: X=`cal $(date +%m) $(date +%Y) | grep -v '' | wc -w` The issue is that I am running the script on the 7th day of... (11 Replies)
Discussion started by: lyoncc
11 Replies

7. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

8. Shell Programming and Scripting

Assigning number of days in the month to a variable

I am writing a script that requires the number of days in any given month. In the shell, I can use the command: cal `date +%m` `date +%Y`| grep -v '' | wc -w to give me the number of days in the month, but when I assign it to a variable: VAR=`cal `date +%m` `date +%Y`| grep -v '' | wc... (3 Replies)
Discussion started by: skaptakalian
3 Replies

9. Shell Programming and Scripting

calculate the number of days left in a month

does any one have any ideas how i would go about calculating the number of days left in the month from a bash script ?. I want to do some operations on a csv file according to the result (8 Replies)
Discussion started by: dunryc
8 Replies

10. Shell Programming and Scripting

Calc number of days in a month

Looking for some help on capturing the number of days in a month to set as a loop counter. Any ideas, please let me know. (3 Replies)
Discussion started by: flounder
3 Replies
Login or Register to Ask a Question