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. ... 293#677293
Bash und rc.xml
Bash und rc.xml
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: Bash und rc.xml
tryRSH 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. ... 293#677293
Code: Select all
sed -i 's/<keyboard>/<keyboard>my code/' rc.xml
Thanks, but did not work. I did try to insert the code directly into your codetry
Code:
sed -i 's/<keyboard>/<keyboard>my code/' rc.xml
Code: Select all
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
Code: Select all
MyCode=`cat /root/Desktop/mycode.xml`
sed -i 's/<keyboard>/<keyboard>$MyCode/' /root/Desktop/rc.xml
Code: Select all
MyCode=`cat /root/Desktop/mycode.xml`
sed -i 's/<keyboard>/<keyboard>'$MyCode'/' /root/Desktop/rc.xml
Code: Select all
MyCode=`cat /root/Desktop/mycode.xml`
sed -i 's/<keyboard>/<keyboard>"$MyCode"/' /root/Desktop/rc.xml
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
Hey Rainer
You need to escape all / occurrences; also you can add a few \n to make the result more readable:
(btw: & instead of the second <keyboard> will simply leave it unchanged and append the rest of string to it.)
Greetings!
You need to escape all / occurrences; also you can add a few \n to make the result more readable:
Code: Select all
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
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
RSH,
Use | as a separator, otherwise you'll have to escape everything.
Cheers,
s
Use | as a separator, otherwise you'll have to escape everything.
Code: Select all
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>|'
s
Uuhh yeah!SFR wrote:Hey Rainer
You need to escape all / occurrences; also you can add a few \n to make the result more readable:
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: Select all
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
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?seaside wrote:RSH,
Use | as a separator, otherwise you'll have to escape everything.
Again, thanks to all.
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]