- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Comparing the months....
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp
Knowledge Base
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 08:19 PM
02-10-2004 08:19 PM
Comparing the months....
Using shell script and awk statements, I manage to get the month and year of the Patch Bundle installed on the system. Now I have to compare month and year of Patch Bundle installed to the Patch Bundle which is desired on the workstation. I am able to do easily comparison of year but not of month. Can anyone suggest how to do this???
In short I have to accomplish:
if [ "march" greater than "november" ];
then
echo "jjjjjjjj"
else
echo "iiiiiiii"
fi
Thanx for your cooperation and help
Regards,
Pankaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 08:22 PM
02-10-2004 08:22 PM
Re: Comparing the months....
january=1
february=2
...
december=12
then compare using if statements.
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 08:32 PM
02-10-2004 08:32 PM
Re: Comparing the months....
Thats good advice
case $month in
January ) let realmonth=1 ;;
---
December ) let realmonth=12 ;;
esac
Same for wantedmonth
Compare 2 results as decimal
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 08:51 PM
02-10-2004 08:51 PM
Re: Comparing the months....
$datestring="january1 february2 march3 april4 etc etc"
$month=`expr "$datestring" : ".*\$monthtest\(.*\) .*"`
This will return the month number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 10:09 PM
02-10-2004 10:09 PM
Re: Comparing the months....
I am exploring the approach suggested by you as it is quite compact and presentable. Can you just explain it further???
Thanx
Pankaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 10:19 PM
02-10-2004 10:19 PM
Re: Comparing the months....
You then just do this as as subroutine or explicitly like
[ `expr "$datetest" : ".*$month1\(.*\) .*`" -gt `expr "$datetest" : ".*$month2\(.*\) .*`" ] && {
# code if month 1 is greater than month 2
}
You can use "if" if you prefer.
It would have been much more compact in perl though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 10:59 PM
02-10-2004 10:59 PM
Re: Comparing the months....
Thats great. The fix is working fine, however, a small hitch is still there. Instead of stopping at the month number i.e. being stopped by a "space" character, it is going ahead.
For monthtest = august, the output is:
*************************************
8 september9 october10 november11 december12
*************************************
I am trying different combinations of the fix but somehow I am not able to crack it and get only the number "8" as display.
Waiting for response,
Pankaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 11:19 PM
02-10-2004 11:19 PM
Re: Comparing the months....
Change the expr to look like the following!
expr "$datestring" : ".*$monthtest\([[:digit:]]\)"
Apologies!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 11:27 PM
02-10-2004 11:27 PM
Re: Comparing the months....
BEGIN{themonth["january"]=1; etc }
Then when you print out the month and year from the patch bundle, instead of printing out the fields (say field 1 was the month and field 2 was the year), you would print out themonth[$1], $2.
Best regards,
Oz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2004 11:56 PM
02-10-2004 11:56 PM
Re: Comparing the months....
That seems to be working fine now. It gives me directly the month no as the output.
However there is a small issue again :-)
This time it works fine only if the output is single digit i.e 1 to 9. But if the month is october or nov or dec then it displays only "1". So how to go about this thing.
Also can you tell me some link/resource as to where can I get the info about the syntax you are using over here like " [[:digit:]]" etc for my better understanding. I will be then using this with logic and not blindly:-)
Thanx for your timely support...
Pankaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2004 02:28 AM
02-11-2004 02:28 AM
Re: Comparing the months....
For example:
MONTH1="march"
YEAR1=2003
MONTH2="July"
YEAR2=2003
JDATE1=$(caljd.sh -I ${MONTH1} 1 ${YEAR1})
JDATE2=$(caljd.sh -I ${MONTH2} 1 ${YEAR2})
if [[ ${JDATE1} -gt ${JDATE2} ]]
then
echo "${MONTH1} ${YEAR1} is later then ${MONTH2} ${YEAR2}"
else
echo "${MONTH2} ${YEAR2} is later than or equal to ${MONTH1} ${YEAR1}"
The -I tells caljd.sh that full case-insensitive monthnames (rather than numeric) are expected. Similarly -i tells caljd.sh that abbreviated monthnames are expected. For a listing of the monthnames, do a locale LC_TIME.
As a bonus, because the locale is utilized. If LANG is properly set, non-English monthnames work without changes -- something that would clobber the other methods.
Invoke as caljd.sh -u for full usage.
Here is caljd.sh, version 2.22.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2004 05:32 PM
02-11-2004 05:32 PM
Re: Comparing the months....
The "[[:digit:]]" matches one digit. It should mathc one or more digits. We can achieve that by add an * after it soit starts to look like this.
expr "$datestring" : ".*$monthtest\([[:digit:]]*\)"
If I actually concentrated a bit more, perhaps I could have saved us all a bit of time by getting it right in the first place :)
Anyway, you can start out on the wonderful road that is "regular expressions" by looking at the man page "man 5 regexp". This isn't easy to follow the first time you read it so you'll have to be a bit patient and ask questions on the forum if you have problems.
The great thing about regular expressions is that they turn up in so many places and understanding them can solve so many problems. But an even better thing about learning them is that when you decide you want to start learning perl, you won't get scared off by the long (and usually quite early) chapters on perl regular expressions which take the whole subject to an almost ridiculous level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2004 09:10 PM
02-11-2004 09:10 PM
Re: Comparing the months....
Thanx for cooperation of you all.
Mark, I had guessed that '*' later on and code is behaving nicely.
Thanx to A.Clay for the wonderful 'perfect' piece of code.
We can close this now.... :-)
Regards,
Pankaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2004 03:10 PM
02-12-2004 03:10 PM
Re: Comparing the months....
Just to be more different...
$ month='Aug'
$ echo `expr 'JanFebMarAprMayJunJulAugSepOctNovDec' : ".*$month" / 3`
8
Hein.