Removing from binary file blocks of 50 bytes and keeping between blocks of 100 bytes

Removing from binary file blocks of 50 bytes and keeping between blocks of 100 bytes

1
NewbieNewbie
1

    Oct 07, 2015#1

    Hi everybody!

    I want to filter a binary file by starting deleting 50 bytes and keeping next 100 bytes, and do this until the end of file.
    The 50 byte blocks are headers that I want to delete and keep only the data blocks of 100 bytes.

    Thanks!

    6,686585
    Grand MasterGrand Master
    6,686585

      Oct 07, 2015#2

      There is no script needed for this task as it can be done with a Perl regular expression Replace in Files using backreferences whereby it does not matter if the binary file to modify is opened in UltraEdit or even better not opened at all.

      Here is this replace coded into a script asking on execution for the file name with full path of the binary file to modify.

      Code: Select all

      // Asking a user for a string written to a variable works only
      // if at least one file is opened in UltraEdit/UEStudio.
      var bNewFileCreated = false;
      if (UltraEdit.document.length < 1)
      {
         UltraEdit.newFile();
         bNewFileCreated = true;
      }
      var sFileName = UltraEdit.getString("Please enter name of binary file with path:",1);
      if (sFileName.length)
      {
         UltraEdit.perlReOn();
         UltraEdit.frInFiles.filesToSearch=0;
         UltraEdit.frInFiles.directoryStart="";
         UltraEdit.frInFiles.searchInFilesTypes=sFileName;
         UltraEdit.frInFiles.ignoreHiddenSubs=false;
         UltraEdit.frInFiles.logChanges=false;
         UltraEdit.frInFiles.matchCase=true;
         UltraEdit.frInFiles.matchWord=false;
         UltraEdit.frInFiles.preserveCase=false;
         UltraEdit.frInFiles.searchSubs=false;
         UltraEdit.frInFiles.regExp=true;
         UltraEdit.frInFiles.unicodeSearch=false;
         UltraEdit.frInFiles.useEncoding=false;
         UltraEdit.frInFiles.replace("(?s).{50}(.{100})","\\1");
      }
      if (bNewFileCreated)
      {
         UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
      }
      Search string (?s).{50}(.{100}) means:

      (?s) ... dot should match really any character (byte) including newline characters, see "." (dot) in Perl regular expressions doesn't include CRLFs? for details.

      .{50} ... match any character (byte) exactly 50 times.

      (...) ... mark the string found by the expression inside parentheses for usage in replace using back-referencing.

      .{100} ... match any character (byte) exactly 100 times.

      The replace string is \1 to reference the 100 bytes matched by the first capturing group. In script one more backslash is used as the backslash character is an escape character in JavaScript strings and must be therefore escaped with one more backslash to pass \1 to the Perl regular expression engine instead of just 1 as it would be done by JavaScript core on using only 1 backslash in replace string.

      The number of replaces made on the single file specified on execution is displayed with a message box because of value false assigned to replace in files property logChanges. No message box would be displayed with value true for this parameter.
      Best regards from an UC/UE/UES for Windows user from Austria