I'm trying to write a script to help automate some VERY tedious manual tasks.
I have groups of fairly large XML files (~3mb+) that I need to edit.
I need to look through the files and parse the XML looking for a certain flag contained in a field. If I find this flag (an integer value) I need to insert XML comments around the entire element (in the <!-- --> style) so that another XML parser will skip over them. After doing that, I later need to remove all the comments from the file (which I think I have).
I found this thread:
https://www.unix.com/shell-programmin...ile-lines.html
Which explains how to insert the comments using SED based on finding the element tag in the file. This is helpful, but I only need to comment elements that contain the "flag" (an int value). Unfortunately, the elements have various names, and aren't in any sort of order.
I was thinking about using PHP (what I'm most familiar with) or maybe Ruby to help parse through the XML to find matching flags, which I'm comfortable with. My problem is how to use/invoke SED once I find a element that needs commenting, and doing so.
This might be something easy, but at the moment I'm having a hard time figuring out which direction to go in. Does anyone have any guidance they'd share with me? Does it sound like I'm heading in the right direction, or am I totally off? Am I overlooking some obvious answer?
I'd much appreciate any help.
- Jeremy