Shell script to get Timezone


 
Thread Tools Search this Thread
Top Forums Programming Shell script to get Timezone
# 1  
Old 02-14-2013
Code Shell script to get Timezone

Hi friends i need to writing a code to use the longitue and latitude to get a time zone. Example below

Code:
            Logitude   Latitude
OMAN     21.9          56.6
BRGHT    27.57        -89.4
BLUGL    26.25        -91.95

latitude lines run horizontally
Longitude are vertical lines

using below example of wget we get the +0400 which is a TIMEZONE . How can we write a program to create a table and put this information in another column.

Code:
wget -O test <URL>

<?xml version="1.0" encoding="ISO-8859-1" ?>
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.xsd">
  <version>1.0</version>
  <location>
    <latitude>21.9</latitude>
    <longitude>56.6</longitude>
  </location>
  <offset>4</offset>
  <suffix>D</suffix>
  <localtime>14 Feb 2013 19:49:48</localtime>
  <isotime>2013-02-14 19:49:48 +0400[/COLOR]</isotime>
  <utctime>2013-02-14 15:49:48</utctime>
  <dst>Unknown</dst>
</timezone>

Appreciate your time and effort.

Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 02-14-2013 at 11:57 AM.. Reason: code tags, got PM
# 2  
Old 02-14-2013
Correct me if I am wrong, so you have an XML with latitude, longitude & timezone and you want to parse this XML file and get these values and put them in table format?

If yes, from the provided XML how do you want your output data look like? It will be better if you can post a sample desired output required from the XML input.
# 3  
Old 02-14-2013
Hi Bipinajith

Thank you for checking on this program .

When you do wget you get the xml format in the output . In that output i would like to take out only 1 value out of the xml file and place it in a table


<?xml version="1.0" encoding="ISO-8859-1" ?>
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.xsd">
<version>1.0</version>
<location>
<latitude>21.9</latitude>
<longitude>56.6</longitude>
</location>
<offset>4</offset>
<suffix>D</suffix>
<localtime>14 Feb 2013 19:49:48</localtime>
<isotime>2013-02-14 19:49:48 +0400[/COLOR]</isotime>
<utctime>2013-02-14 15:49:48</utctime>
<dst>Unknown</dst>
</timezone>

Output should be

OMAN 21.9 56.6 +0400
BRGHT 27.57 -89.4 <value>
BLUGL 26.25 -91.95 <value>

appreciate your time .



Quote:
Originally Posted by bipinajith
Correct me if I am wrong, so you have an XML with latitude, longitude & timezone and you want to parse this XML file and get these values and put them in table format?

If yes, from the provided XML how do you want your output data look like? It will be better if you can post a sample desired output required from the XML input.

Last edited by ajayram_arya; 02-14-2013 at 02:00 PM..
# 4  
Old 02-14-2013
I'm not sure from where you are reading the location: OMAN, I don't see that in the XML!

You can write an awk program to extract the desired values, here is a code & output:
Code:
awk -F'[<>]' '/latitude/ {
                LA=$3;
        } /longitude/ {
                LO=$3;
        } /isotime/ {
                TS=$3;
                sub(/.* /,x,TS);
                sub(/\[.*/,x,TS);
        } END {
                print LA, LO, TS;
} ' xmlfile
21.9 56.6 +0400

# 5  
Old 02-14-2013
Where does BRGHT come from? It's not in the file.

If all you want to do is extract the timezone, awk '/isotime/ { sub(/<.*/,"",$3) ; print $3 }' but I suspect we could find a better solution to your whole problem here if you'd say it.
# 6  
Old 02-14-2013
First column will not show in xml because i have taken only 2 values longitude and latitude to get the result using wget on a URL which creates an xml file on output which i pasted in the initial post.




Quote:
Originally Posted by Corona688
Where does BRGHT come from? It's not in the file.

If all you want to do is extract the timezone, awk '/isotime/ { sub(/<.*/,"",$3) ; print $3 }' but I suspect we could find a better solution to your whole problem here if you'd say it.
---------- Post updated at 01:18 PM ---------- Previous update was at 12:15 PM ----------

This gives me a syntax error

a@b.com$ awk -F'[<>]' '/latitude/ {
LA=$3;
} /longitude/ {
LO=$3;
} /isotime/ {
TS=$3;
sub(/.* /,x,TS);
sub(/\[.*/,x,TS);
} END {
print LA, LO, TS;
} ' output3
awk: syntax error near line 7
awk: illegal statement near line 7
awk: syntax error near line 8
awk: illegal statement near line 8




Quote:
Originally Posted by bipinajith
I'm not sure from where you are reading the location: OMAN, I don't see that in the XML!

You can write an awk program to extract the desired values, here is a code & output:
Code:
awk -F'[<>]' '/latitude/ {
                LA=$3;
        } /longitude/ {
                LO=$3;
        } /isotime/ {
                TS=$3;
                sub(/.* /,x,TS);
                sub(/\[.*/,x,TS);
        } END {
                print LA, LO, TS;
} ' xmlfile
21.9 56.6 +0400

# 7  
Old 02-14-2013
Considering that they bend the lines around nations, this is the approximate or solar time zone, I suppose? Each one is 15 degrees ( 360 / 24 ).

If you can go from lat/long to nation somehow, then you might get the time zone: Time zone - Wikipedia, the free encyclopedia
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Getting numeric timezone on HP-UX

Hi I thought the UNIX command date is universal and so I have been using date +%z to get the numberic timezone offset (e.g. -0500) however on HP-UX, this is not returning expected results; on my machine it returns the name of the time zone (e.g. EST) not numbers. does anyone know... (2 Replies)
Discussion started by: flagman5
2 Replies

2. UNIX for Dummies Questions & Answers

Need help with Timezone locale.

HI Gurus, I have a issue. One of our applications needs the data loads with the timezone (CST) but our zones run on GMT. I tried to change the TZ value under /etc/default/init value but it seems to effect the the whole zone. Is there any way I can just set up the TZ as CST for a particular user.... (2 Replies)
Discussion started by: rama krishna
2 Replies

3. Red Hat

changing timezone

Hi, I would like to change time zone Linux from IST to US/Canada but not getting the option , I have run the command setup -> timezone configuration but not getting the option of us/canada or pacific us/canada. Please suggest. Regards, Manoj (1 Reply)
Discussion started by: manoj.solaris
1 Replies

4. Shell Programming and Scripting

Script to change Timezone(Solaris)

india 22/11/2009 10:00:00 AM sweden 22/11/2009 01:30:00 PM As mentioned above i will get the datetime string from my customer and i need to change that String into diffrnt timezone as mentioned above. ---------- Post updated at 01:54 AM ---------- Previous update was at 01:01 AM ----------... (5 Replies)
Discussion started by: vikas482
5 Replies

5. AIX

Timezone Setting

Hi On several AIX 5.3 LPARs the timezone is currrently set to: TZ=NZST-12NZDT,M9.5.0/02:00,M4.1.0/03:00 Daylight savings in NZ starts on Sun 28th Sep 2008, which is the fourth Sunday. Do I need to change my TZ variable to NZST-12NZDT,M9.4.0/02:00,M4.1.0/03:00 or will AIX interpret the fifth... (2 Replies)
Discussion started by: KiwiP
2 Replies

6. UNIX for Advanced & Expert Users

Timezone

HI ; I got Solaris8 installed oon Sunfire V440 .I have TZ=GMT in /etc/TIMEZONE , but when i log in as root i see the date in GMT+1. So i have every time to "set TZ=GMT ; export $TZ" . How can i set the TZ=GMT at the startup defenitely. Thanks :) (7 Replies)
Discussion started by: oss
7 Replies

7. UNIX for Dummies Questions & Answers

Timezone Problems

Hi all, i have running an hp-ux a-class server with hp-ux 11.00. All users without root are using the wrong timezone. root is using METDST, all others are using EDT. I have checked /etc/profile /etc/TIMEZONE /etc/ntp.conf and the .profiles from the users. But there is no failure... Is... (4 Replies)
Discussion started by: ortsvorsteher
4 Replies

8. UNIX for Dummies Questions & Answers

timezone

Hi, i am searching to change the timezone on a HP-UX11 system. Since last weekend the summertime started i am not able to change the time to the new time, every day the time changes back to wintertime. I think the problem is that the server is on the wrong timezone. Can someone help me please?... (1 Reply)
Discussion started by: eddyvdv
1 Replies

9. UNIX for Dummies Questions & Answers

Timezone

Hi, I got an question about changing timezone thrue command line on a SunOS Release 4.1.2 without restarting the computer. Now it's set on WET and I want to set the timezone to CET (GMT +1) Plz somebody help me. Regards Novisern:confused: (5 Replies)
Discussion started by: Novisern
5 Replies

10. UNIX for Dummies Questions & Answers

Timezone

Hello again, under hp-ux i have a file /etc/TIMEZONE. here is definied which timezone i am. i dont know who reads this file to set after reading the timezone under /usr/lib/tztab. my 2 questions, who reads the file /etc/TIMEZONE ( which service ) and do i need in the first line to set my... (6 Replies)
Discussion started by: ortsvorsteher
6 Replies
Login or Register to Ask a Question