Sed question: something to do with timezone in wget (Solved)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
Lassar
Posts: 235
Joined: Tue 08 Jul 2014, 20:01

Sed question: something to do with timezone in wget (Solved)

#1 Post by Lassar »

I am a newbie when it comes to sed.

I found this on the net.

Code: Select all

timezone=`wget -O - -q http://geoip.ubuntu.com/lookup | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p'`
I want to replace the value in <timezone>value</timezone> in file /root/.kodi/userdata/guisettings.xml with the variable timezone.

How do you change the 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p' so sed will replace value in <TimeZone>value</TimeZone> so value becomes $timezone?

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

Re: Sed question: something to do with timezone in wget

#2 Post by musher0 »

Lassar wrote:I am a newbie when it comes to sed.

I found this on the net.

Code: Select all

timezone=`wget -O - -q http://geoip.ubuntu.com/lookup | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p'`
I want to replace the value in <timezone>value</timezone> in file /root/.kodi/userdata/guisettings.xml with the variable timezone.

How do you change the 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p' so sed will replace value in <TimeZone>value</TimeZone> so value becomes $timezone?
Hello Lassar.

I don't know sed. I never had a need for it.

I know that replaceit, awk and bash can also do string replacements. Bash is the
fastest because it processes strings internally.

The simplest to use for a newbie -- and IMO the simplest to use, period -- is
replaceit: http://www.pldaniels.com/replaceit. If you don't know how to
compile it, there are a couple of ready-made pets lying around on this forum.

My take on your problem:

Code: Select all

TZ="`curl http://geoip.ubuntu.com/lookup 2>/dev/null | tr ">" "\n" | awk -F"<" '$NF ~ /\/TimeZone/ { print $1 }'`";echo $TZ
Try it; it works!

What's left would be to find the actual name of the data to change in file
/root/.kodi/userdata/guisettings.xml (which I do not have, so I cannot help you with
this part) and issue this replaceit command:

Code: Select all

replaceit --input=/root/.kodi/userdata/guisettings.xml "Whatever" "$TZ"
If the kodi xml file is executable (usually xml files are not), you would need to run
chmod +x on it afterwards, because replaceit removes any executable bit from a
file before processing it.

IHTH.
Last edited by musher0 on Sun 31 Dec 2017, 01:34, edited 2 times in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: Sed question: something to do with timezone in wget

#3 Post by MochiMoppel »

Lassar wrote:I want to replace the value in <timezone>value</timezone> in file /root/.kodi/userdata/guisettings.xml with the variable timezone.
Here your wget code produces a $timezone value of 'Asia/Tokyo'.
The forward slash '/' conflicts with sed's customary '/' separation character, so I replaced it with '@' (assuming that no timezone string contains this character):

Code: Select all

sed -i "s@<timezone>.*</timezone>@<timezone>$timezone</timezone>@" /root/.kodi/userdata/guisettings.xml
The code reads /root/.kodi/userdata/guisettings.xml and replaces <timezone>.*</timezone> (the tags and anything between them) with the new tags <timezone>$timezone</timezone>, containing your $timezone value.
Lassar also wrote:How do you change the 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p' so sed will replace value in <TimeZone>value</TimeZone> so value becomes $timezone?
I'm confused now by "replace value in <TimeZone>value</TimeZone>". Please check guisettings.xml. Is it <timezone> or <TimeZone>? XML and sed are case sensitive.

Lassar
Posts: 235
Joined: Tue 08 Jul 2014, 20:01

Re: Sed question: something to do with timezone in wget

#4 Post by Lassar »

MochiMoppel wrote:

Code: Select all

sed -i "s@<timezone>.*</timezone>@<timezone>$timezone</timezone>@" /root/.kodi/userdata/guisettings.xml
The code reads /root/.kodi/userdata/guisettings.xml and replaces <timezone>.*</timezone> (the tags and anything between them) with the new tags <timezone>$timezone</timezone>, containing your $timezone value.
Just tried it out.

Works like a charm. Thank you for your help.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#5 Post by musher0 »

And of course I did not answer you... I spent some time investigating your problem
and suggesting a solution, and I don't even get a thanks "in passing". Ah.

I'm not asking you to adopt my solution, I'm asking for a semblance of polite
behavior from a member of the same forum.

So you don't know how to live in society, do you, Lassar? It would have cost you six
letters, a comma, my nick and a period.

I am furious. :x :evil:
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Lassar
Posts: 235
Joined: Tue 08 Jul 2014, 20:01

Thanks for trying.

#6 Post by Lassar »

musher0 wrote:And of course I did not answer you... I spent some time investigating your problem
and suggesting a solution, and I don't even get a thanks "in passing". Ah....

I am furious.
Thanks for the suggestion.

I asked about sed, not replaceIt.

First: I am looking for a command already in Xenialpup64.

Second: I can't find any documentation on it on the web.

Third: It does not even look powerful enough to do what I want.

Post Reply