The time now is Sun 19 May 2013, 12:46
All times are UTC - 4 |
| Author |
Message |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: 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
_________________ Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1700 Location: Burghaslach, Germany
|
Posted: 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
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: 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
_________________ Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: 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
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 832
|
Posted: 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
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: 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:
| 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
|
| 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.
_________________ Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
|
|
Back to top
|
|
 |
|
|
|
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
|