How to delete all before a string and all after another string in all files of a folder?

How to delete all before a string and all after another string in all files of a folder?

2

    Apr 26, 2023#1

    Dear all,

    I am not necessarily looking for the answer, more the best way forward.

    We have a bunch of files that I think come from an Adobe system. The files look like containing a thumbnail image as well as some metadata about the image. I can open them in a browser window and see an image. When I open the file in UE, I can see that there is a bunch of non-printable characters before and after the metadata which is in a well-formed XML format.

    What I need to end up with is just a file containing the XML portion. As such, I need to remove whatever is before the opening XML tag and whatever is after the ending XML tag. I can do this manually in UE and end up with exactly the right file which I need for processing downstream. BUT ... I have about 0.5 millions of files to process.

    Can UE do this for me in an automated fashion? If so, what is the best way to go about this? If not, what else would you recommend?

    Regards
    Basil

    6,684586
    Grand MasterGrand Master
    6,684586

      Apr 26, 2023#2

      This can be done easily with a Perl regular expression Replace in Files execution on using UltraEdit for Windows v24.00 or newer.

      The Perl regular expression search string (?s)\A(?:(?!<\?xml).)+|(?<=</xmltag>).+\z matches everything from beginning of buffer (file) to last byte before <?xml and everything after </xmltag> to end of file. It is important for the second part that the end tag </xmltag> exists only once in each file which is usually the case for valid XML files. Otherwise a more complex regular expression for bytes at end of file would be needed for the task. The replace string is an empty string.

      I strongly recommend to make a backup of the folder with all the files to modify before running that Perl regular expression replace in files as there is no undo available on something goes wrong.
      Best regards from an UC/UE/UES for Windows user from Austria

      2

        Apr 27, 2023#3

        Mofi,

        Thanks so much for that, it worked an absolute treat. I think you've probably saved me about a couple of days worth of effort (for me anyway) or even more! If you are ever in Sydney, make sure you hit me up for drink or three!

        Cheers
        Basil