Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Yes, I know I could do that. I mentioned it in my question, where I explicitly stated that I didn't want to do it because it would be slow and tedious (largely because of the overhead of running it once per file, rather than running xmlstarlet once with hundreds of filename args). After setting the namespace, xmlstarlet processed all 350 .xhtml chapter files in 0.196 seconds (on my ancient Phenom II 1090T system)....about the time it took xml_grep to process just one file (0.191 seconds). Commented Sep 15, 2022 at 23:22
  • I feel one of us may be missunderstanding the other: I believe the above commands would process all of your input files in one go. The point is that I would have thought this is then no longer tedious, which I took to be the objection in your post. Although this would quite possibly have a longer runtime, it would be likely much less than writing your original post/getting a cup of tea, etc. Commented Sep 16, 2022 at 9:54
  • Yes, and the script does exactly what I said I didn't want to do - run xml_grep once for each file in a loop. There's significant overhead in starting a perl program 350 times in a loop with one filename per execution versus starting a compiled program once and having it process 350 filename args. It's not that I can't write a trivial script like yours above (especially since it's only a few extra lines in the script I've already written to unzip & re-zip the .epub file containing the .xhtml files), it's that I don't want to, for the reasons I clearly stated in my question. Commented Sep 17, 2022 at 4:33
  • My question was not "how do i write a trivial shell script and have a nice cup of tea?", it was "how do I get xmlstarlet to do what it's supposed to be able to do?". I have received a good answer to my actual question. Commented Sep 17, 2022 at 4:35