I am using Arch which was updated a couple of weeks ago. Packages is use are
- Arch 6.0.10-arch2-1
- BASH 5.1.16(1)-release
- gnu sed 4.9
- gnu grep 3.8
- openbox 3.6.1
Within my Openbox rc.xml text file I have two lines as follows
<!-- <keybind key="Right"> -->
<keybind key="s-Up">
I wish to frequently toggle/swap the above two lines for the below two lines using a script
<!-- <keybind key="s-Up"> -->
<keybind key="Right">
This allows me to quickly change a keybinding without tediously editing my keybindings set-up text file (rc.xml) every time.
The script I have so far is below, and is not working, though I know it is close.
I'm not too bothered how this toggling is achieved, but having spent a significant amount of time already on this it would be nice to get below script working.
The sed expressions below that do the text swapping work as they should.
The if statement seems to do the first sed swap if the condition is met but not the second sed swap if the condition is not met, which is the issue.
var_a=""
#var_a=$(grep -zoP "<\!\-\- <keybind key=\"Right\"> \-\->\n\n<keybind key=\"s-Up\">" /home/kes/Dropbox/lubuntu-rc.xml | sed ':a;N;$!ba;s|\n\n||g')
var_a=$(grep -zoP "<\!\-\- <keybind key=\"Right\"> \-\->\n\n<keybind key=\"s-Up\">" /home/kes/Dropbox/lubuntu-rc.xml | tr -d '\n' )
# result of grep is
# <!-- <keybind key="Right"> --><keybind key="s-Up">
echo $var_a; sleep 0.5
#if [[ -z ! "$var_a" ];then
if [[ '$var_a'=='<!-- <keybind key="Right"> --><keybind key="s-Up">' ]]; then
sed -ie ':a;N;$!ba;s|<!-- <keybind key="Right"> -->\n\n<keybind key="s-Up">|<!-- <keybind key="s-Up"> -->\n\n<keybind key="Right">|g' /home/kes/Dropbox/lubuntu-rc.xml
else
sed -ie ':a;N;$!ba;s|<!-- <keybind key="s-Up"> -->\n\n<keybind key="Right">|<!-- <keybind key="Right"> -->\n\n<keybind key="s-Up">|g' /home/kes/Dropbox/lubuntu-rc.xml
fi
grepandsedtags for a reason. Future users will likely choose the same tags for a similar problem, so the original tags could help them find the question. Thexmlandtext-processingtags are a good addition, but not replacement, I think. It's similar to X-Y problems, where you better not remove theX-related tags.