LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2011, 05:55 PM   #1
thebeav
LQ Newbie
 
Registered: Jan 2011
Posts: 25

Rep: Reputation: 1
Trying to figure out a date command


Newbieness glaring brightly here Working through a Unix/Linux book trying to figure out the basics of the shell. I am trying to figure out how to run a command with bash to find the last day of the month in any given month. I read the man pages for date and cal but I am stupid or missing something. I figured out many things but this is the only one that has me pulling my hair out at this time. Thanks in advance.
 
Old 01-13-2011, 08:14 PM   #2
tligda
LQ Newbie
 
Registered: Jan 2011
Posts: 9

Rep: Reputation: 1
Quote:
cal <month> <year> | sed '/^$/d' | tail -1 | awk '{printf $NF}'
via
 
Old 01-13-2011, 10:21 PM   #3
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 872

Rep: Reputation: 112Reputation: 112
Well what is it your trying to get? This is a example using the date command with a backup

tar cvzpf homebackup-`date +%m-%d-%y` /home/username

If you noticed I put the date command in ``. So give a little more info if this doesn't cover what you need
 
Old 01-13-2011, 10:54 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi,

this, e.g., will also give you the name of the day:
Code:
cal feb 2000|sort -nr | awk 'FNR==1{a=NF;b=$NF}/^[^ [:digit:]]/{print $a,b}'
If this is not what you were looking for then you'll need to clarify a bit more.
 
Old 01-13-2011, 11:31 PM   #5
thebeav
LQ Newbie
 
Registered: Jan 2011
Posts: 25

Original Poster
Rep: Reputation: 1
Thank you, now I have to digest this. Thanks for the help. Much appreciated.

for the last day of October
Code:
echo $(cal 10 2011) | awk '{print $NF}'
for the last day with of October including name of the day
Code:
cal 10 2011|sort -nr | awk 'FNR==1{a=NF;b=$NF}/^[^ [:digit:]]/{print $a,b}'

Last edited by thebeav; 01-13-2011 at 11:33 PM.
 
Old 01-14-2011, 12:56 AM   #6
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 872

Rep: Reputation: 112Reputation: 112
oops sorry OP i just realized I had misread your question.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help in date command mmhs Linux - Newbie 2 12-17-2010 04:37 PM
using date command sumeet inani Linux - Newbie 9 05-06-2010 06:40 AM
I can not figure out what this command should be. dvdljns Linux From Scratch 28 12-22-2009 04:43 AM
date command aetucker1 Linux - General 3 01-21-2005 01:57 PM


All times are GMT -5. The time now is 08:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration