LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trying to figure out a date command (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-figure-out-a-date-command-856178/)

thebeav 01-13-2011 04:55 PM

Trying to figure out a date command
 
Newbieness glaring brightly here :o 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.

tligda 01-13-2011 07:14 PM

Quote:

cal <month> <year> | sed '/^$/d' | tail -1 | awk '{printf $NF}'
via

jmc1987 01-13-2011 09:21 PM

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

crts 01-13-2011 09:54 PM

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.

thebeav 01-13-2011 10:31 PM

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}'

jmc1987 01-13-2011 11:56 PM

oops sorry OP i just realized I had misread your question.


All times are GMT -5. The time now is 07:35 PM.