I'm wondering where I could go to learn how to edit file sections that cross multiple lines. I'm wanting to write scripts that will add Gnome menu entries for all users on a system for scripts I write, etc. I can search an replace simple examples with sed, but this seems more complex.
I am on a 'doz system in a hotel right now so I can't post the actual file, but the Gnome menu entry has a structure similar to this:
Say I need to change the markups for the dasher.desktop file from <Exclude> to <Include> and </Exclude> to </Include>?
What If I wanted to add a new <Include></Include> section for a new .desktop file?
Compounding this is that there is variable whitespace indentation depending on how deep into the structure one needs to go and it would be nice to keep the formatting for readability and a nicer, more polished look.
Basically, what is the technique for finding something, and then modifying something on lines above and/or below it OR finding a section, and then adding something on a line below that section without modifying that line in the process.
I don't mind learning myself, but I need pointed in the right direction. I'm not sure where to start. This seems like a bit of a big job for sed. If someone would want to code an example, I'm up for that too as I can learn from that (hey, learning is fun, right?)
you won't be able to do this reliably with sed.
it's non trivial I'd say to get it right.
it's an xml file you're better off using a proper XML processor.
I use alacarte for single user, but unfortunately, it only adds things for the user, not for the system (running as root doesn't work either, of course).
I have seen websites like above (the Gnome one is the best giving examples to hand-edit files and create system-wide meus and can be found at Editing System Menus), but I'm more interested in automation. I manage many computers and I would like to write a script to add these to the system menus, but there may be some user customizing, too, so I can't just make one global menu system and deploy it (also some are using Linux Mint and Ubuntu so different menus are necessary).
I'm not sure how alacarte and the one that comes with gnome works.
This is what I hate about many things going to an XML format. Makes command line manipulation difficult. I'm sure there is some module to import for python (which I am in the process of learning), perl, c, etc, but right now, that is a little beyond my scope. But I'm getting pretty good with shell programming.
Thank you for confirming what I was fearing about not being able to use sed for this.
Anyone know of a good python module for me to look into to edit XML files?