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 24 Apr 2014, 17:58
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Bash und rc.xml
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
RSH


Joined: 05 Sep 2011
Posts: 2036
Location: Germany

PostPosted: Sun 13 Jan 2013, 14:56    Post subject:  Bash und rc.xml  

Hi.

I want to configure the rc.xml file from openbox wm, actually adding key bindings to switch desktop from keyboard. I know how and where to insert the code into the rc.xml file manually.

But I want to oi this from bash script.

So, I need to read the whole content of the rc.xml file until xml tag <keyboard> was found. Then I need to insert my own code and after this I need to get the rest of the rc.xml file to build up the new increased file.

I could do this without any help from you experts, using a loop, reading line by line until <keyboard> is found, echo my code and reading the rest of the rc.xml file line by line.

I'm just asking for a less code solution, maybe a two liner or something like that?

Thanks,

RSH

Would you please have a look, here: http://murga-linux.com/puppy/viewtopic.php?p=677293#677293

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2481
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Sun 13 Jan 2013, 15:12    Post subject: Re: Bash und rc.xml  

RSH wrote:
Hi.

I want to configure the rc.xml file from openbox wm, actually adding key bindings to switch desktop from keyboard. I know how and where to insert the code into the rc.xml file manually.

But I want to oi this from bash script.

So, I need to read the whole content of the rc.xml file until xml tag <keyboard> was found. Then I need to insert my own code and after this I need to get the rest of the rc.xml file to build up the new increased file.

I could do this without any help from you experts, using a loop, reading line by line until <keyboard> is found, echo my code and reading the rest of the rc.xml file line by line.

I'm just asking for a less code solution, maybe a two liner or something like that?

Thanks,

RSH

Would you please have a look, here: http://murga-linux.com/puppy/viewtopic.php?p=677293#677293

try
Code:
sed -i 's/<keyboard>/<keyboard>my code/' rc.xml
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2036
Location: Germany

PostPosted: Sun 13 Jan 2013, 16:49    Post subject:  

Quote:
try
Code:
sed -i 's/<keyboard>/<keyboard>my code/' rc.xml

Thanks, but did not work. I did try to insert the code directly into your code

Code:
sed -i 's/<keyboard>/<keyboard>'<keybind key="A-1"><action name="Desktop"><desktop>1</desktop></action></keybind><keybind key="A-2"><action name="Desktop"><desktop>2</desktop></action></keybind><keybind key="A-3"><action name="Desktop"><desktop>3</desktop></action></keybind><keybind key="A-4"><action name="Desktop"><desktop>4</desktop></action></keybind>/' /root/Desktop/rc.xml


and tried to read it from file.

Code:
MyCode=`cat /root/Desktop/mycode.xml`
sed -i 's/<keyboard>/<keyboard>$MyCode/' /root/Desktop/rc.xml


Code:
MyCode=`cat /root/Desktop/mycode.xml`
sed -i 's/<keyboard>/<keyboard>'$MyCode'/' /root/Desktop/rc.xml


Code:
MyCode=`cat /root/Desktop/mycode.xml`
sed -i 's/<keyboard>/<keyboard>"$MyCode"/' /root/Desktop/rc.xml


Nothing works

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 882

PostPosted: Sun 13 Jan 2013, 17:11    Post subject:  

Hey Rainer

You need to escape all / occurrences; also you can add a few \n to make the result more readable:

Code:
sed -i 's/<keyboard>/&\n<keybind key="A-1"><action name="Desktop"><desktop>1<\/desktop><\/action><\/keybind>\n<keybind key="A-2"><action name="Desktop"><desktop>2<\/desktop><\/action><\/keybind>\n<keybind key="A-3"><action name="Desktop"><desktop>3<\/desktop><\/action><\/keybind>\n<keybind key="A-4"><action name="Desktop"><desktop>4<\/desktop><\/action><\/keybind>/' /root/Desktop/rc.xml

(btw: & instead of the second <keyboard> will simply leave it unchanged and append the rest of string to it.)

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 878

PostPosted: Sun 13 Jan 2013, 17:48    Post subject:  

RSH,

Use | as a separator, otherwise you'll have to escape everything.
Code:
sed  's|<keyboard>|<keyboard><keybind key="A-1"><action name="Desktop"><desktop>1</desktop></action></keybind><keybind key="A-2"><action name="Desktop"><desktop>2</desktop></action></keybind><keybind key="A-3"><action name="Desktop"><desktop>3</desktop></action></keybind><keybind key="A-4"><action name="Desktop"><desktop>4</desktop></action></keybind>|'


Cheers,
s
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2036
Location: Germany

PostPosted: Sun 13 Jan 2013, 17:55    Post subject:  

SFR wrote:
Hey Rainer

You need to escape all / occurrences; also you can add a few \n to make the result more readable:

Uuhh yeah!

The escapes. I've had this once in a bash script with jpeps. This is weird stuff, if one doesn't really know or understand, how to use this.

However, thank you for the useful (as always) code. Will play with it and surely reach some state of success - later.

Meanwhile I have used my "Pascal Working-Path" and solved it for testings with this code: Laughing
Code:
MyCode=`cat /root/Desktop/mycode.xml`

---


INSERT="true"
while read LINE
do
   echo "$LINE" >> /root/Desktop/new_rc.xml
   if [[ "$LINE" == *keyboard* ]]; then
      if [ "$INSERT" = "true" ]; then
         INSERT="false"
         echo "$MyCode" >> /root/Desktop/new_rc.xml
         sleep .1
      fi
   fi
done < /root/Desktop/rc.xml

Laughing
seaside wrote:
RSH,

Use | as a separator, otherwise you'll have to escape everything.

Yes, thanks. This is a very useful extension to my bash knowledge. I've always wondered why sometimes "/" is used and sometimes "|" is used in such sed codes?

Again, thanks to all.

_________________
LazY Puppy
RSH's DNA
SARA B.
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.0596s ][ Queries: 11 (0.0031s) ][ GZIP on ]