* how to get the last word from file
@ Ned
` Trevor Astrope
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Ned @ UTC (permalink / raw)
To: Speakup is a screen review system for Linux.
Hi list,
I am using the cal command to get current month. What I need for my shell script is how many days are there in the current month, that is, the last listed date for that month is that very number.
How can I get that number?
cal | tail -1
and then what?
Many thanks!
Ned
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: how to get the last word from file how to get the last word from file Ned @ ` Trevor Astrope ` Ned ` David Bruzos ` (2 subsequent siblings) 3 siblings, 1 reply; 11+ messages in thread From: Trevor Astrope @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. Try something like this: date +"%d" --date="`date +\"%b 1 1 month\"` 1 day ago" There's probably a simpler way using the date command, but that should work. Hth, Trevor On Tue, 29 Mar 2005, Ned wrote: > Hi list, > I am using the cal command to get current month. What I need for my shell script is how many days are there in the current month, that is, the last listed date for that month is that very number. > How can I get that number? > cal | tail -1 > and then what? > > Many thanks! > Ned > _______________________________________________ > Speakup mailing list > Speakup@braille.uwo.ca > http://speech.braille.uwo.ca/mailman/listinfo/speakup > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file ` Trevor Astrope @ ` Ned ` Gregory Nowak 0 siblings, 1 reply; 11+ messages in thread From: Ned @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. Sure it works-- but looks like Chinese to me... "`... 1 day ago... I'll study it. Many thanks By the way, anybody knows of a remote system where I can check the teraterm pro? Those at school wouldn't let me get connected with anything other than the putty because of the security reasons; I need to ask them for a special permition to use this client, but I want to know how much better is it than the putty. Is it only telnet? Thanks a lot! Ned ----- Original Message ----- From: "Trevor Astrope" <astrope@tabbweb.com> To: "Speakup is a screen review system for Linux." <speakup@braille.uwo.ca> Sent: Tuesday, March 29, 2005 12:35 PM Subject: Re: how to get the last word from file > Try something like this: > > date +"%d" --date="`date +\"%b 1 1 month\"` 1 day ago" > > > There's probably a simpler way using the date command, but that should > work. > > > Hth, > > Trevor > > On Tue, 29 Mar 2005, Ned wrote: > >> Hi list, >> I am using the cal command to get current month. What I need for my shell >> script is how many days are there in the current month, that is, the last >> listed date for that month is that very number. >> How can I get that number? >> cal | tail -1 >> and then what? >> >> Many thanks! >> Ned >> _______________________________________________ >> Speakup mailing list >> Speakup@braille.uwo.ca >> http://speech.braille.uwo.ca/mailman/listinfo/speakup >> >> > > _______________________________________________ > Speakup mailing list > Speakup@braille.uwo.ca > http://speech.braille.uwo.ca/mailman/listinfo/speakup > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file ` Ned @ ` Gregory Nowak 0 siblings, 0 replies; 11+ messages in thread From: Gregory Nowak @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 No, teraterm pro also supports ssh, though I'm not sure if it's both ssh1 and ssh2, or just ssh1. Greg On Tue, Mar 29, 2005 at 01:00:36PM -0700, Ned wrote: > Sure it works-- > but looks like Chinese to me... > "`... > 1 day ago... > I'll study it. > Many thanks > By the way, anybody knows of a remote system where I can check the teraterm > pro? > Those at school wouldn't let me get connected with anything other than the > putty because of the security reasons; I need to ask them for a special > permition to use this client, but I want to know how much better is it than > the putty. Is it only telnet? > > > Thanks a lot! > Ned - -- web site: http://www.romuald.net.eu.org gpg public key: http://www.romuald.net.eu.org/pubkey.asc skype: gregn1 (authorization required, add me to your contacts list first) - -- Free domains: http://www.eu.org/ or mail dns-manager@EU.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFCSbbX7s9z/XlyUyARAtOyAKCfHZrPdsB5drv2ZvKfx/2ga/LXewCguvPI QcjO0Fu8c2JURAtRKFrPXig= =KNQA -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file how to get the last word from file Ned ` Trevor Astrope @ ` David Bruzos ` Ari Moisio ` Ralph W. Reid 3 siblings, 0 replies; 11+ messages in thread From: David Bruzos @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. This command will do it on my system: cal | tr ' ' '\n' | tail -n 2 I have to put 2 as arg for tail, because my cal command prints a blank line at the end... DB On Tue, Mar 29, 2005 at 12:17:43PM -0700, Ned wrote: > Hi list, > I am using the cal command to get current month. What I need for my shell script is how many days are there in the current month, that is, the last listed date for that month is that very number. > How can I get that number? > cal | tail -1 > and then what? > > Many thanks! > Ned > _______________________________________________ > Speakup mailing list > Speakup@braille.uwo.ca > http://speech.braille.uwo.ca/mailman/listinfo/speakup ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file how to get the last word from file Ned ` Trevor Astrope ` David Bruzos @ ` Ari Moisio ` Ned ` Ralph W. Reid 3 siblings, 1 reply; 11+ messages in thread From: Ari Moisio @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. Hi! Quick & dirty:-) echo $(cal) | tail -c 3 -- arimo On Tue, 29 Mar 2005, Ned wrote: > Hi list, > I am using the cal command to get current month. What I need for my shell script is how many days are there in the current month, that is, the last listed date for that month is that very number. > How can I get that number? > cal | tail -1 > and then what? > > Many thanks! > Ned > _______________________________________________ > Speakup mailing list > Speakup@braille.uwo.ca > http://speech.braille.uwo.ca/mailman/listinfo/speakup > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file ` Ari Moisio @ ` Ned 0 siblings, 0 replies; 11+ messages in thread From: Ned @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. ... provided that on most systems the last 3 bytes contain the last date of a month. What about this approach: cal | tail +3 | wc -c Many ways to do this... Many Thanks. Ned ----- Original Message ----- From: "Ari Moisio" <arimo@netsonic.fi> To: "Speakup is a screen review system for Linux." <speakup@braille.uwo.ca> Sent: Tuesday, March 29, 2005 12:55 PM Subject: Re: how to get the last word from file > Hi! > > Quick & dirty:-) > echo $(cal) | tail -c 3 > > > -- > arimo > > On Tue, 29 Mar 2005, Ned wrote: > >> Hi list, >> I am using the cal command to get current month. What I need for my shell >> script is how many days are there in the current month, that is, the last >> listed date for that month is that very number. >> How can I get that number? >> cal | tail -1 >> and then what? >> >> Many thanks! >> Ned >> _______________________________________________ >> Speakup mailing list >> Speakup@braille.uwo.ca >> http://speech.braille.uwo.ca/mailman/listinfo/speakup >> > > _______________________________________________ > Speakup mailing list > Speakup@braille.uwo.ca > http://speech.braille.uwo.ca/mailman/listinfo/speakup ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file how to get the last word from file Ned ` (2 preceding siblings ...) ` Ari Moisio @ ` Ralph W. Reid ` Chuck Hallenbeck ` Ned 3 siblings, 2 replies; 11+ messages in thread From: Ralph W. Reid @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. On Tue, Mar 29, 2005 at 12:17:43PM -0700, Ned wrote: > Hi list, > I am using the cal command to get current month. What I need for my shell script is how many days are there in the current month, that is, the last listed date for that month is that very number. > How can I get that number? > cal | tail -1 > and then what? > > Many thanks! > Ned The above command line will produce a blank line because the last line produced by `cal` is a blank line. If you are looking specifically for days in the current month (as opposed to a more general last-word-in file search), the following is one of several ways to produce it: if [ `cal | grep -c 31` == 1 ]; then echo 31 elif [ `cal | grep -c 30` == 1 ]; then echo 30 elif [ `cal | grep -c 29` == 1 ]; then echo 29 elif [ `cal | grep -c 28` == 1 ]; then echo 28 else echo Cal did not produce a calendar. fi HTH, and have a _great_ day! -- Ralph. N6BNO. Wisdom comes from central processing, not from I/O. rreid@sunset.net http://personalweb.sunset.net/~rreid ...passing through The City of Internet at the speed of light! _PI = 4 * ARCTAN (1) ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file ` Ralph W. Reid @ ` Chuck Hallenbeck ` Ned 1 sibling, 0 replies; 11+ messages in thread From: Chuck Hallenbeck @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. Or else you do this: cal | tail -c 4 Chuck -- The Moon is Waning Gibbous (73% of Full) "Things are in the saddle, and they ride mankind." Ralph Waldo Emerson Visit my download site at http://www.mhcable.com/~chuckh ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file ` Ralph W. Reid ` Chuck Hallenbeck @ ` Ned ` Ralph W. Reid 1 sibling, 1 reply; 11+ messages in thread From: Ned @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. This is yet to be seen! Wow, what a syntax. semicolon at the end of if, elif, then, and the most apealing is that fi at the end. Thanks a lot! It's a totally new stuff to me. Is there a case structure in bash? That would fit here just perfectly. Many thanks! Ned ----- Original Message ----- From: "Ralph W. Reid" <rreid@sunset.net> To: "Speakup is a screen review system for Linux." <speakup@braille.uwo.ca> Sent: Wednesday, March 30, 2005 1:16 PM Subject: Re: how to get the last word from file > On Tue, Mar 29, 2005 at 12:17:43PM -0700, Ned wrote: >> Hi list, >> I am using the cal command to get current month. What I need for my shell >> script is how many days are there in the current month, that is, the last >> listed date for that month is that very number. >> How can I get that number? >> cal | tail -1 >> and then what? >> >> Many thanks! >> Ned > > The above command line will produce a blank line because the last line > produced by `cal` is a blank line. If you are looking specifically > for days in the current month (as opposed to a more general > last-word-in file search), the following is one of several ways to > produce it: > > if [ `cal | grep -c 31` == 1 ]; > then > echo 31 > elif [ `cal | grep -c 30` == 1 ]; > then > echo 30 > elif [ `cal | grep -c 29` == 1 ]; > then > echo 29 > elif [ `cal | grep -c 28` == 1 ]; > then > echo 28 > else > echo Cal did not produce a calendar. > fi > > HTH, and have a _great_ day! > > -- > Ralph. N6BNO. Wisdom comes from central processing, not from I/O. > rreid@sunset.net http://personalweb.sunset.net/~rreid > ...passing through The City of Internet at the speed of light! > _PI = 4 * ARCTAN (1) > > _______________________________________________ > Speakup mailing list > Speakup@braille.uwo.ca > http://speech.braille.uwo.ca/mailman/listinfo/speakup > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to get the last word from file ` Ned @ ` Ralph W. Reid 0 siblings, 0 replies; 11+ messages in thread From: Ralph W. Reid @ UTC (permalink / raw) To: Speakup is a screen review system for Linux. As you have probably seen, others have posted _much_ simpler solutions to this problem than I did. There is a `case` statement in bash, but you would have to determine how to check for different values while performing only a single `cal` command. See your favorite man page for bash by running `man bash` on your favorite linux box--it is big, but there is a lot of good stuff in there. As a side note, you might be able to use a simple word count to get the days in any given month since `cal` should always produce the same headings, and then a range of numbers ranging from 28 through 31 depending on the month and whether or not the month is February during a leap year. The following seems to work, and uses the math feature available in `bash` to assign the result to a variable, and then echos the result for output: let totaldays=`cal | wc -w`-9 echo $totaldays There should always be 9 words of header info produced by `cal`, so subtracting the count of the words in the header (9) leaves the number of dates displayed for the month. I might have recognized this way of producing the total days if I had slept a little before posting the somewhat lengthy and complicated solution shown below--maybe next time I will not be so hasty with my post if it seems a little messy again;). Just one more of many possible ways of producing the output you seem to be looking for :) . HTH, and have a _great_ day! On Wed, Mar 30, 2005 at 03:48:02PM -0700, Ned wrote: > This is yet to be seen! > Wow, what a syntax. > semicolon at the end of if, elif, then, > and the most apealing is that fi at the end. > Thanks a lot! > It's a totally new stuff to me. > Is there a case structure in bash? That would fit here just perfectly. > > Many thanks! > Ned > ----- Original Message ----- > From: "Ralph W. Reid" <rreid@sunset.net> > To: "Speakup is a screen review system for Linux." <speakup@braille.uwo.ca> > Sent: Wednesday, March 30, 2005 1:16 PM > Subject: Re: how to get the last word from file > > > >On Tue, Mar 29, 2005 at 12:17:43PM -0700, Ned wrote: > >>Hi list, > >>I am using the cal command to get current month. What I need for my shell > >>script is how many days are there in the current month, that is, the last > >>listed date for that month is that very number. > >>How can I get that number? > >>cal | tail -1 > >>and then what? > >> > >>Many thanks! > >>Ned > > > >The above command line will produce a blank line because the last line > >produced by `cal` is a blank line. If you are looking specifically > >for days in the current month (as opposed to a more general > >last-word-in file search), the following is one of several ways to > >produce it: > > > >if [ `cal | grep -c 31` == 1 ]; > >then > >echo 31 > >elif [ `cal | grep -c 30` == 1 ]; > >then > >echo 30 > >elif [ `cal | grep -c 29` == 1 ]; > >then > >echo 29 > >elif [ `cal | grep -c 28` == 1 ]; > >then > >echo 28 > >else > >echo Cal did not produce a calendar. > >fi > > > >HTH, and have a _great_ day! > > > >-- > >Ralph. N6BNO. Wisdom comes from central processing, not from I/O. > >rreid@sunset.net http://personalweb.sunset.net/~rreid > >...passing through The City of Internet at the speed of light! > >_PI = 4 * ARCTAN (1) -- Ralph. N6BNO. Wisdom comes from central processing, not from I/O. rreid@sunset.net http://personalweb.sunset.net/~rreid ...passing through The City of Internet at the speed of light! 1 = x^0 ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~ UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
how to get the last word from file Ned
` Trevor Astrope
` Ned
` Gregory Nowak
` David Bruzos
` Ari Moisio
` Ned
` Ralph W. Reid
` Chuck Hallenbeck
` Ned
` Ralph W. Reid
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).