Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 18 Oct 2018, 16:25
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Sed question: something to do with timezone in wget (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
Lassar

Joined: 08 Jul 2014
Posts: 221

PostPosted: Sat 30 Dec 2017, 17:59    Post subject:  Sed question: something to do with timezone in wget (Solved)  

I am a newbie when it comes to sed.

I found this on the net.

Code:
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?
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 12816
Location: Gatineau (Qc), Canada

PostPosted: Sat 30 Dec 2017, 19:56    Post subject: Re: Sed question: something to do with timezone in wget  

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

I found this on the net.
Code:
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:
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:
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.

_________________
musher0
~~~~~~~~~~
Fidèle elle commença, ainsi elle restera. (Prov. canadien) /
Faithful she began, so will she stay. (Canadian prov.)

Last edited by musher0 on Sat 30 Dec 2017, 21:34; edited 2 times in total
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1662
Location: Japan

PostPosted: Sat 30 Dec 2017, 21:29    Post subject: Re: Sed question: something to do with timezone in wget  

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:
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.
Back to top
View user's profile Send private message 
Lassar

Joined: 08 Jul 2014
Posts: 221

PostPosted: Sun 31 Dec 2017, 01:44    Post subject: Re: Sed question: something to do with timezone in wget  

MochiMoppel wrote:

Code:
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.
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 12816
Location: Gatineau (Qc), Canada

PostPosted: Sun 31 Dec 2017, 01:53    Post subject:  

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. Mad Evil or Very Mad

_________________
musher0
~~~~~~~~~~
Fidèle elle commença, ainsi elle restera. (Prov. canadien) /
Faithful she began, so will she stay. (Canadian prov.)
Back to top
View user's profile Send private message 
Lassar

Joined: 08 Jul 2014
Posts: 221

PostPosted: Mon 01 Jan 2018, 14:01    Post subject: Thanks for trying.  

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.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0543s ][ Queries: 12 (0.0032s) ][ GZIP on ]