Tapatalk

Split file data to seperate tabs

Split file data to seperate tabs

5
NewbieNewbie
5

    Jan 27, 2023#1

    Hello,

    I've reviewed several of the split/loop posts, but none really cover what I'm looking for. And I am unsure how to achieve the expected result with a find macro.
    I have a small example below of a before and after. Looking to break by Issue Number to separate tabs. The Issue Number is in field position 62. (Issues are PM01 and HMI2 in examples.)

    Thanks in advance for any thoughts on how this might work - Jen
     
    BEFORE

    Code: Select all

    3099999911   12355555COMPANY NAME                             PM01 000000000  OTHERMISC00000000  4250000000
    3099999900    000000000000124                           0000000000000     2344334432          222777772 00000000000
    3099999900     39993003030                                   00000000000000   3444343433           22222222 000000000000~
    3099999911    1244444                                                               PM01  000000000  OTHERMIS123549       00000000000
    3099999900    000000000000124                           0000000000000     2344334432          222777772 00000000000~
    3099999911   12355555COMPANY NAME                             HMI2 000000000  OTHERMISC00000000  4250000000
    3099999900    000000000000124                           0000000000000     2344334432          222777772 00000000000
    3099999900     39993003030                                   00000000000000   3444343433           22222222 000000000000~
    AFTER (what I’m looking for)
    First tab:

    Code: Select all

    3099999911   12355555COMPANY NAME                             PM01 000000000  OTHERMISC00000000  4250000000
    3099999900    000000000000124                           0000000000000     2344334432          222777772 00000000000
    3099999900     39993003030                                   00000000000000   3444343433           22222222 000000000000~
    3099999911    1244444                                                               PM01  000000000  OTHERMIS123549       00000000000
    3099999900    000000000000124                           0000000000000     2344334432          222777772 00000000000~
    Next tab:

    Code: Select all

    3099999911   12355555COMPANY NAME                             HMI2 000000000  OTHERMISC00000000  4250000000
    3099999900    000000000000124                           0000000000000     2344334432          222777772 00000000000
    3099999900     39993003030                                   00000000000000   3444343433           22222222 000000000000~

    6,688587
    Grand MasterGrand Master
    6,688587

      Jan 27, 2023#2

      The following small macro was recorded, edited and finally tested with the small example using UltraEdit for Windows v2022.2.0.34.

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      Top
      PerlReOn
      Clipboard 9
      Loop 0
      Find MatchCase RegExp "^.{62}[A-Z].+(?:\r?\n|\r|$)(?:(?!.{62}[A-Z]).+(?:\r?\n|\r|$))*"
      IfNotFound
      ExitLoop
      EndIf
      Copy
      NewFile
      Paste
      IfColNumGt 1
      InsertLine
      EndIf
      Top
      Find MatchCase RegExp "^.{62}\K[A-Z][0-9A-Z]+"
      SaveAs "^s.txt"
      CloseFile
      EndLoop
      ClearClipboard
      Clipboard 0
      Top
      
      The first case-sensitive Perl regular expression searches for a line with a Latin letter in upper case ([A-Z]) after 62 characters (.{62}) from beginning of a line (^) and matches one or more characters in the line (.+) up to DOS/Windows or Unix or MAC line termination or end of file (?:\r?\n|\r|$) and matches further all other lines below not having a Latin letter in upper case after 62 characters from beginning of a line (?!.{62}[A-Z]). That regular expression find should always match an entire block to copy into a new file which is done next with using the user clipboard 9.

      After the paste is checked if the last line of the new file has a line termination. If that is not the case for the last block copied from input file, a line termination is inserted at end of the file. Each new file is saved in the current directory with the issue number as file name and file extension .txt. It would be good to insert the full path left to ^c on macro command SaveAs to avoid saving the new files in a not expected directory.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Jan 27, 2023#3

        Good Morning,

        This works terrific to break to from Tilde to Tilde, but it's a bit more complex (that's where I ran into problems too - sorry if I didn't explain well). So it would have to be something like - if string start 30999991 and Issue Field (field start 62) != not equal the start of the next 309999901, break all of same Issue to new tab.

        I've attached a new example of before and after.  The Issues in the sample files would be JB01 and ABC1.  And it would be breaking out All of the JB01 to one tab and All of the ABC1 to another tab ...and loop and so for larger files with more Issues.

        Hoping this makes more sense and appreciate so much in advance - Jen 
        BEFORE.txt (1.54 KiB)   2
        AFTER.txt (1.57 KiB)   2

        6,688587
        Grand MasterGrand Master
        6,688587

          Jan 28, 2023#4

          Please note first that the macro and script solution posted below work only if all issue blocks with same issue number are stored together in the input file, i.e. JB0102222222279, JB0102222222279, ABC1102222222279 works, but not JB0102222222279, ABC1102222222279, JB0102222222279.

          The task is difficult to do with a macro because of variables and nested loops are not supported by UltraEdit macros. It is necessary to use two macros and the UltraEdit regular expression engine to work around these limitations.

          The first macro must be named NextIssueNumber and must have the properties:

          Code: Select all

          [ ] Show cancel dialog for this macro
          [X] Continue if searched string not found
          [X] Disable screen refresh during macro playback
          The macro code for the macro NextIssueNumber is:

          Code: Select all

          Loop 0
          Find MatchCase RegExp "%309999901 ???????????????????????????????????????????????????^c"
          IfNotFound
          ExitLoop
          EndIf
          EndLoop
          Find MatchCase RegExp "%309999901"
          IfFound
          GotoLine 0 1
          Else
          Bottom
          EndIf
          The macro NextIssueNumber is played as a submacro to search first in a loop for lines starting with 309999901 and having the issue number in the user clipboard 8 and next moving the caret to the beginning of the next line starting with 309999901 or the end of the file.

          The second macro is the main macro and can have a name of your choice like SplitIssues and must have the properties:

          Code: Select all

          [ ] Show cancel dialog for this macro
          [X] Continue if searched string not found
          [X] Disable screen refresh during macro playback
          The macro code for the macro SplitIssues is:

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          Top
          Clipboard 8
          ToggleBookmark
          UltraEditReOn
          Loop 0
          Find MatchCase RegExp "%309999901 ???????????????????????????????????????????????????"
          IfNotFound
          ExitLoop
          EndIf
          Find MatchCase RegExp "[0-9A-Z]+"
          Copy
          PlayMacro 1 "NextIssueNumber"
          ToggleBookmark
          PreviousBookmarkSelect
          Clipboard 9
          Copy
          ToggleBookmark
          GotoBookMark -1
          NewFile
          Paste
          Clipboard 8
          IfColNumGt 1
          InsertLine
          EndIf
          SaveAs "^c.txt"
          CloseFile
          EndLoop
          ToggleBookmark
          ClearClipboard
          Clipboard 9
          ClearClipboard
          Clipboard 0
          Bottom
          Both macros must be stored in same macro file as otherwise the submacro NextIssueNumber cannot not be played by the main macro SplitIssues.

          This macro first moves the caret to top of the file, selects user clipboard 8 as clipboard to use during macro execution for the current issue number and bookmarks the first line.

          Then it searches for the next issue number on a line starting with 309999901 beginning from column 62 consisting of digits and upper case Latin letters. The found issue number is copied into user clipboard 8.

          The submacro is played to move the caret to the beginning of the line starting with 309999901 and having a different issue number or to the end of the file.

          That line is also bookmarked as it is the beginning of the next issue block or the end of the file in case of the last issue block is currently processed.

          The caret is moved upwards to the beginning of the block with current issue number in user clipboard 8 with selection of all lines from current caret position at the beginning of the next issue block or the end of the file.

          The selected block is copied to user clipboard 9. Then the bookmark at beginning of the current issue block is removed and the caret is moved to the beginning of the next issue block or the end of the file.

          A new file is created into which the copied block is pasted and if the caret is not at the beginning of a new line, a line termination is appended to the end of the new file. The file is saved with the issue number in user clipboard 9 with file extension .txt in the current directory before being closed which makes the input file again the active file at least if no other file is opened too (recommended).

          The last bookmark and the two used user clipboards are cleared after all issue blocks are saved into separate files and the caret is explicitly moved to the end of the file to indicate a successful processing of the input file.

          There are usually used for such task nowadays UltraEdit scripts instead of macros because of variables and nested loops can be used in a script. Here is a script solution with comments explaining the code.

          Code: Select all

          // See https://forums.ultraedit.com/viewtopic.php?f=52&t=6762 for information about the function GetFilePath.
          function GetFilePath (CompleteFileNameOrDocIndexNumber)
          {
             var sFilePath = "";
             var sFullFileName = "";
             var nLastDirDelim = -1;
          
             var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 0;
          
             if (typeof(CompleteFileNameOrDocIndexNumber) == "string")
             {
                sFullFileName = CompleteFileNameOrDocIndexNumber;
          
                nLastDirDelim = sFullFileName.lastIndexOf("|");
          
                if (nLastDirDelim < 0)
                {
                   var nLastSlash = sFullFileName.lastIndexOf("/");
                   var nLastBackSlash = sFullFileName.lastIndexOf("\\");
                   nLastDirDelim = (nLastBackSlash > nLastSlash) ? nLastBackSlash : nLastSlash;
                }
                if (nLastDirDelim < 0)
                {
                   if (nOutputType == 2)
                   {
                      UltraEdit.messageBox("File path can't be determined from \""+sFullFileName+"\"!","GetFilePath Error");
                   }
                   else if (nOutputType == 1)
                   {
                      if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
                      UltraEdit.outputWindow.write("GetFilePath: File path can't be determined from \""+sFullFileName+"\"!");
                   }
                   return sFilePath;
                }
             }
             else
             {
                if (UltraEdit.document.length < 1)
                {
                   if (nOutputType == 2)
                   {
                      UltraEdit.messageBox("No document is open currently!","GetFilePath Error");
                   }
                   else if (nOutputType == 1)
                   {
                      if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
                      UltraEdit.outputWindow.write("GetFilePath: No document is open currently!");
                   }
                   return sFilePath;
                }
          
                var nDocumentNumber = -1;
                if (typeof(CompleteFileNameOrDocIndexNumber) == "number")
                {
                   nDocumentNumber = CompleteFileNameOrDocIndexNumber;
                }
          
                if (nDocumentNumber >= UltraEdit.document.length)
                {
                   if (nOutputType == 2)
                   {
                      UltraEdit.messageBox("A document with index number "+nDocumentNumber+" does not exist!","GetFilePath Error");
                   }
                   else if (nOutputType == 1)
                   {
                      if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
                      UltraEdit.outputWindow.write("GetFilePath: A document with index number "+nDocumentNumber+" does not exist!");
                   }
                   return sFilePath;
                }
          
                if (nDocumentNumber < 0)
                {
                   sFullFileName = UltraEdit.activeDocument.path;
                   if (UltraEdit.activeDocument.isFTP())
                   {
                      nLastDirDelim = sFullFileName.lastIndexOf("|");
                      if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
                   }
                }
                else
                {
                   sFullFileName = UltraEdit.document[nDocumentNumber].path;
                   if (UltraEdit.document[nDocumentNumber].isFTP())
                   {
                      nLastDirDelim = sFullFileName.lastIndexOf("|");
                      if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("/");
                   }
                }
                if (nLastDirDelim < 0) nLastDirDelim = sFullFileName.lastIndexOf("\\");
          
                if (nLastDirDelim < 0)
                {
                   if (nOutputType == 2)
                   {
                      UltraEdit.messageBox("File path can't be determined from a new file!","GetFilePath Error");
                   }
                   else if (nOutputType == 1)
                   {
                      if (!UltraEdit.outputWindow.visible) UltraEdit.outputWindow.showWindow(true);
                      UltraEdit.outputWindow.write("GetFilePath: File path can't be determined from a new file!");
                   }
                   return sFilePath;
                }
             }
          
             if (sFullFileName.charAt(nLastDirDelim) != '|')
             {
                nLastDirDelim++;
                sFilePath = sFullFileName.substring(0,nLastDirDelim);
             }
             else
             {
                sFilePath = sFullFileName.substring(0,nLastDirDelim) + "/";
             }
             return sFilePath;
          }
          
          if (UltraEdit.document.length > 0)  // Is any file opened?
          {
             // Defined variables used in the script code below.
             var nLineNumberBegin = 1;
             var nLineNumberEnd = 1;
             var nFileIndex = UltraEdit.activeDocumentIdx;
             var sFullFilePath = GetFilePath(UltraEdit.activeDocument.path);
             var sIssueNumber;
          
             // Define environment for this script.
             UltraEdit.insertMode();
             if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
             else if (typeof(UltraEdit.document[nFileIndex].columnModeOff) == "function") UltraEdit.document[nFileIndex].columnModeOff();
          
             // Defined the parameters for the case-sensitive Perl regular expressions finds used below.
             UltraEdit.perlReOn();
             UltraEdit.document[nFileIndex].findReplace.mode=0;
             UltraEdit.document[nFileIndex].findReplace.matchCase=true;
             UltraEdit.document[nFileIndex].findReplace.matchWord=false;
             UltraEdit.document[nFileIndex].findReplace.regExp=true;
             UltraEdit.document[nFileIndex].findReplace.searchDown=true;
             if (typeof(UltraEdit.document[nFileIndex].findReplace.searchInColumn) == "boolean") {
                UltraEdit.document[nFileIndex].findReplace.searchInColumn=false;
             }
          
             // Move the caret to top of the input file.
             UltraEdit.document[nFileIndex].top();
             // Select user clipboard 9 for copying the issue blocks into a new file.
             UltraEdit.selectClipboard(9);
             // Clear the output window as the file names are written into it.
             UltraEdit.outputWindow.clear();
          
             // Search for a line beginning with 309999901 and having at column 62 a
             // string consisting of one or more digits or upper case Latin letters
             // and select just this string beginning at column 62 if found at all.
             while(UltraEdit.document[nFileIndex].findReplace.find("^309999901 .{51}\\K[0-9A-Z]+"))
             {
                // Assign the selected issue number to the string variable sIssueNumber.
                sIssueNumber = UltraEdit.document[nFileIndex].selection;
                // Search for a line beginning with 309999901 and having at column 62
                // not the same issue number as stored in variable sIssueNumber.
                if (UltraEdit.document[nFileIndex].findReplace.find("^309999901 .{51}(?!"+sIssueNumber+")"))
                {
                   // Move the caret to beginning of next issue block.
                   UltraEdit.document[nFileIndex].gotoLine(0,1);
                }
                else
                {  // Move the caret to the end of the file.
                   UltraEdit.document[nFileIndex].bottom();
                }
          
                // Get the line number of next issue block or the end of the file.
                nLineNumberEnd = UltraEdit.document[nFileIndex].currentLineNum;
                // Select everything upwards to beginning of current issue block.
                UltraEdit.document[nFileIndex].gotoLineSelect(nLineNumberBegin,1);
                // Copy the selection into user clipboard 9.
                UltraEdit.document[nFileIndex].copy();
                // Move caret to beginning of next issue block or the end of the file.
                UltraEdit.document[nFileIndex].gotoLine(nLineNumberEnd,1);
                // That line is the beginning of the next issue block.
                nLineNumberBegin = nLineNumberEnd;
          
                // Create a new file, paste the copied block, make sure the last
                // line of the file has also a line termination and save and close
                // the file with issue number as file name and file extension .txt
                // in the directory of active file on script start.
                UltraEdit.newFile();
                UltraEdit.activeDocument.paste();
                if (UltraEdit.activeDocument.isColNumGt(1))
                {
                   UltraEdit.activeDocument.insertLine();
                }
                UltraEdit.saveAs(sFullFilePath+sIssueNumber+".txt");
                UltraEdit.outputWindow.write(UltraEdit.activeDocument.path);
                UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
             }
          
             // Clear the user clipboard 9, select the system clipboard and
             // explicitly move the caret to the end of the active file to
             // indicate a successful processing of the file.
             UltraEdit.clearClipboard();
             UltraEdit.selectClipboard(0);
             UltraEdit.document[nFileIndex].bottom();
          
             // Turn off writing the script execution status into the output window.
             UltraEdit.outputWindow.showStatus=false;
             UltraEdit.outputWindow.showWindow(true);
          }
          
          The lines with UltraEdit.outputWindow can be removed all from the script file or there is commented out just the last but one line with the scripting command UltraEdit.outputWindow.showWindow(true); if there should not be opened the output window with the list of fully qualified file names created during the script execution.

          It would be also possible to write a different and faster executed script loading first all text data in active file into memory of the JavaScript core engine interpreting UltraEdit scripts as one string, find each block to write into a separate file in memory and of course write the text blocks into the appropriate files if the input file is never too large to be loaded into internal memory of the JavaScript core engine. There is usually no problem to load a file with less than 4 MB into JavaScript core engine memory as string for fast processing it.
          Best regards from an UC/UE/UES for Windows user from Austria

          5
          NewbieNewbie
          5

            Jan 28, 2023#5

            Hello,

            First of all, thank you so much for all the replies - so appreciate.  With the macros provided, not sure how to cobble them together so the one runs as a submacro - tried and failed miserably (also did the file naming as instructed - no go).  And for the alternative script provided, that didn't seem to work. But that's most likely due to my sad instructions. That and another wrinkle will be that the Issue Number doesn't always have an upper-case letter (can also be all numeric).

            But with that, I have a script that might work and was wondering if you could configure in UltraEdit format. It hopefully handles the trailer records (309999900) where the Issue for review is in another position (23, 27) vs (62,66).  So when the Issue actually changes, it's just copying to top of file cutting, pasting in new tab and rinse and repeat (or so I hope).

            Thanks in advance and sorry to pester - Jen

            Code: Select all

            const fs = require('fs');
            
            const data = fs.readFileSync('data.txt', 'utf8').split('\n');
            let previousIssue = data[0].substring(62, 66);
            let currentIssue;
            let output = '';
            
            data.forEach(line => {
              currentIssue = line.substring(62, 66);
              if (currentIssue === previousIssue || line.substring(23, 27) === previousIssue) {
                // go to next line
                return;
              }
              else {
                // select all previous and current line, cut and copy to new file
                output += previousIssue + '\n' + line + '\n';
                previousIssue = currentIssue;
              }
            });
            
            fs.writeFileSync('newfile.txt', output);
            
            This script reads in a file called "data.txt" and splits it into an array of lines. It then initializes a variable "previous Issue" to the first line's issue, and uses a forEach loop to iterate through each line in the data. If the current line has the same issue as the previous line (either in position 62-66 or 23-27), the loop goes to the next line. If the issue has changed, the script concatenates the previous issue and the current line to a variable "output", and updates the "previous Issue" variable to the current line's issue. Finally, the script writes the "output" variable to a new file called "newfile.txt".

            6,688587
            Grand MasterGrand Master
            6,688587

              Jan 28, 2023#6

              You have not yet posted which version of UltraEdit is used by you on which platform with which user interface mode. I suppose therefore that there is used currently latest UltraEdit v2022.2.0.34 on Windows and developed and tested the macro solution with that version of UltraEdit on Windows.

              The macro and the script work also for issue numbers consisting only of digits in comparison to the macro in the first post which required that the first character is an upper case Latin letter due to the different regular expression.

              The step by step instructions for creation of the two macros stored together in a macro file for UltraEdit for Windows v2022.2.0.34 used with ribbon mode are:
              1. Click on last ribbon tab Advanced in third group Macro on the item Configure to open the Edit/Create Macro dialog window.
              2. Click on button New macro to open the Macro Definition dialog window.
              3. Enter the string NextIssueNumber as Macro name, or copy and paste that string from the browser window, and set the three properties as posted. The field for Hotkey is kept empty on clicking next on the button OK.
              4. Copy the macro code from browser window and paste the code into the multi-line edit field on left side of Edit/Create Macro dialog window with replacing the three commands already shown here by selecting them first before pasting the macro code.
              5. Click once again on the button New macro to open the Macro Definition dialog window.
              6. Enter the string SplitIssues  as Macro name, or copy and paste that string from the browser window, and set the three properties as posted. The field for Hotkey is kept empty on clicking next on the button OK.
              7. There is shown now the prompt Do you wish to update the macro? This must be confirmed with a click on button Yes to get NextIssueNumber updated with the pasted code.
              8. There must be again selected the three macro commands before copying and pasting the second macro code from browser window into left multi-line edit field of the macro SplitIssues.
                Attention: The code contains the command PlayMacro 1 "NextIssueNumber". It is required that this macro already exists and has exactly that name (case-sensitve). Otherwise UltraEdit would remove this command on next step but one step silently from the macro code.
              9. Click on the X symbol of the Edit/Create Macro dialog window.
              10. There is shown once again the prompt Do you wish to update the macro? This must be confirmed with a click on button Yes to get the macro SplitIssues updated with the pasted code.
              11. Click on last ribbon tab Advanced in third group Macro on the small down arrow right to the item Configure to open the popup menu. Click on the fourth menu item Save all macros.
              12. Select a directory for storing the macro file. A good choice would be creating the directory macros in the directory %APPDATA%\IDMComp\UltraEdit and selecting this directory. Enter as macro File name SplitIssues and click on button Save to save the two currently loaded and just created macros into the macro file %APPDATA%\IDMComp\UltraEdit\macros\SplitIssues.mac.
                Please note that the directory path %APPDATA%\IDMComp\UltraEdit\ can be copied and pasted into the edit field of the File name and the folder is opened on pressing the key RETURN or ENTER. Then click on the symbol with the tooltip Create New Folder in the toolbar of the dialog window and create the folder macros which is next double clicked to open it.
              13. Click on last ribbon tab Advanced in fifth group Configure on the command Settings to open the Configuration dialog window, select in the tree on left side Directories, click on right side on second button Browse right to the edit field of  Default macro directory, select the folder %APPDATA%\IDMComp\UltraEdit\macros or simply copy and paste that path from browser window into the edit field for the Folder, click on button Select Folder and close the Configuration dialog window with a click on X symbol of the window.
              14. If that macro file with the two macros should be always automatically loaded on startup of UltraEdit, click on last ribbon tab Advanced in third group Macro on the small down arrow right to the item Configure to open the popup menu a second time. Click this time on the fifth menu item Set macro for auto-load. Browse to the macro file %APPDATA%\IDMComp\UltraEdit\macros\SplitIssues.mac and click on button Set.
              There can be opened now the input file to split into separate files. The macro SplitIssues can be played now to split up the issues in opened file into separate files.

              There are in total five different methods on how to run a macro on a file:
              1. A shortcut can be created which starts UltraEdit with first argument /fni and the input file name as second argument and /m,e="%APPDATA%\IDMComp\UltraEdit\macros\SplitIssues.mac/ SplitIssues" as third argument to open the specified file, execute the macro once and exit UltraEdit which is forced to run as new instance even if another instance of UltraEdit is already running.
              2. A hotkey or chord can be defined additionally for the macro SplitIssues with clicking on Macro Configure popup menu item Configure macros and this change is also saved by using once again Save all macros. Then just the hotkey or chord can be pressed on macro file with macro SplitIssues being currently loaded to run this macro once on the active file.
              3. The first menu item Play multiple times in popup menu of Macro item Play macro can be used to open the Play Macro dialog window to select the macro SplitIssues and Play it 1 times.
              4. There can be clicked on ribbon tab Layout on check box item Macros to open the Macro List view on which a double click on macro SplitIssues results in playing the macro once on active file.
              5. The ribbon can be customized to add a new ribbon tab with a new ribbon group with the command SplitIssues added to run in future this macro on macro file loaded with a click on its symbol in the additional ribbon tab.
              The posted script can be used as follows:
              1. Open a new file being ANSI encoded and pasting into this file the script code. The file should be saved with file name SplitIssues.js, best in the directory scripts in folder %APPDATA%\IDMComp\UltraEdit. It is possible to use any other folder like it is possible to use also for the macro file any other folder. The advantage of saving macro or script files in subdirectories of the UltraEdit application data directory is the possibility to backup them together with the UltraEdit user configuration files by using Backup settings on last ribbon tab Advanced.
              2. Click on last ribbon tab Advanced in fourth group Script on second command All scripts to open the Scripts dialog window.
              3. Click on button Add, browse to just saved script file, select it, enter a useful Description and click on Open. There can be added also a Hokey or Chord for executing the script in future on active file by pressing the hotkey or the key combination of the chord (multi-key assignment). Click on button OK.
              The script can be executed now at any time on an opened file which can be even a new file containing the lines and not saved at all with a file name.

              There are in total five different methods on how to play a script on a file:
              1. A shortcut can be created which starts UltraEdit with first argument /fni and the input file name as second argument and /s,e="%APPDATA%\IDMComp\UltraEdit\scripts\SplitIssues.js" as third argument to open the specified file, execute the script and exit UltraEdit which is forced to run as new instance even if another instance of UltraEdit is already running.
              2. A hotkey or chord can be defined additionally for the script SplitIssues as described already above in the Scripts dialog window for execution of the script by key on active file.
              3. There can be clicked on the last ribbon tab Advanced in fourth group Script on item Play script and next on the script SplitIssues.js to run the script on active file.
              4. There can be clicked on ribbon tab Layout on check box item Scripts to open the Script list view on which a double click on script SplitIssues.js results in playing the script on active file.
              5. The ribbon can be customized to add a new ribbon tab with a new ribbon group with the command SplitIssues.js added to run in future this script with a click on its symbol in the additional ribbon tab.
              The UltraEdit macro/script can be extended to open itself the input file on having always the same name and being always stored in the same directory and close that file also automatically after finishing splitting it up into several separate files.
              Best regards from an UC/UE/UES for Windows user from Austria

              5
              NewbieNewbie
              5

                Jan 29, 2023#7

                Thanks again and trying to work through this. Here's my UltraEdit version - version 26.00.0.48.

                The prompt window for Macro Definition is a bit different, but all else is same. So here's the only problem I'm running into. I go through all and come to the final Save All. If I pull in data in the already open session and press Ctrl+M, the macro works EXCELLENT!!! But once saved to my UltraEdit macro folder and reloaded in a new session, it does not work. So it must be something I'm doing wrong in the save process.

                Below are the steps I'm doing. I must be missing something because I'm following the steps and it seems the Save and Reload is what's killing me.

                Thanks - Jen

                PS I attached saved version that doesn't work upon upload in new session which was later removed by Mofi.

                Steps:

                Advanced> Configure> Edit Macro
                New Macro> MacroName=NextIssueNumber >
                Paste in

                Code: Select all

                Loop 0
                Find MatchCase RegExp "%309999901 ???????????????????????????????????????????????????^c"
                IfNotFound
                ExitLoop
                EndIf
                EndLoop
                Find MatchCase RegExp "%309999901"
                IfFound
                GotoLine 0 1
                Else
                Bottom
                EndIf
                New Macro > Macro Name = SplitIssues >
                Paste in

                Code: Select all

                InsertMode
                ColumnModeOff
                HexOff
                Top
                Clipboard 8
                ToggleBookmark
                UltraEditReOn
                Loop 0
                Find MatchCase RegExp "%309999901 ???????????????????????????????????????????????????"
                IfNotFound
                ExitLoop
                EndIf
                Find MatchCase RegExp "[0-9A-Z]+"
                Copy
                PlayMacro 1 "NextIssueNumber"
                ToggleBookmark
                PreviousBookmarkSelect
                Clipboard 9
                Copy
                ToggleBookmark
                GotoBookMark -1
                NewFile
                Paste
                Clipboard 8
                IfColNumGt 1
                InsertLine
                EndIf
                SaveAs "^c.txt"
                CloseFile
                EndLoop
                ToggleBookmark
                ClearClipboard
                Clipboard 9
                ClearClipboard
                Clipboard 0
                Bottom
                X Out of dialog Window

                "Yes" to Wish to Update

                Select Configure > Save All Macros > Save as "SplitIssues" to a folder created on my desktop

                Close Out

                Open New Session with data>SplitIssues from saved location

                Ctrl+M

                Nothing!

                6,688587
                Grand MasterGrand Master
                6,688587

                  Jan 29, 2023#8

                  You made now everything right with one exception: The hotkey Ctrl+M is assigned to command Play again in the Macro menu/group. This command plays the last played or recorded macro once again. But there is no macro played or recorded before on starting a new UltraEdit session and loading a macro file. UltraEdit plays therefore the first macro loaded from the macro file which is in this case the submacro NextIssueNumber and not the main macro SplitIssues which is stored second in the macro file.

                  It is possible to have the two macros saved in reverse order in the macro file SplitIssues.mac by creating first the macro SplitIssues while the submacro NextIssueNumber does not yet exist resulting in macro command PlayMacro 1 "NextIssueNumber" missing in macro code on updating the code of just newly created macro SplitIssues. Next is created the submacro NextIssueNumber. Then is edited the first created macro SplitIssues to insert the missing macro command PlayMacro 1 "NextIssueNumber" and now both macros are saved using Save all macros. Now the macro file SplitIssues.mac contains first the macro SplitIssues and second the macro NextIssueNumber making it possible to run the first macro SplitIssues after loading the macro file with pressing Ctrl+M.

                  I restored UE 26.00.0.48 from my archives, loaded first the macro file SplitIssues.mac created by you, executed explicitly the macro SplitIssues on opened file BEFORE.txt and it worked fine. Then I recreated the macro file SplitIssues.mac as described above. I tested this macro file as well as the script solution with UE 26.00.0.48 on BEFORE.txt and both worked and produced the same two files ABC1102222222279.txt and JB0102222222279.txt.

                  It would be definitely better to insert on macro command SaveAs also a full directory path left to ^c to control where the new files are stored as it is really unpredictable which directory is the current working directory of the running UltraEdit process on execution of the macro. I have had to search once for the created files because of the current working directory was not the directory containing BEFORE.txt. The order of the macros in the macro file SplitIssues.mac does not change on making an edit on macro SplitIssues and use command Save all macros to save both macros with the modification again into SplitIssues.mac.

                  BTW: Your JavaScript code is not best for small files on which it is possible to load the entire file into memory of JavaScript interpreter. I could code an UltraEdit script solution which works as performant as possible for files being not too large to be loaded completely into memory of JavaScript interpreter embedded in UltraEdit if you are interested in such an UltraEdit script with minimal execution time. The script posted by me should work also for a file with several hundred MB or even some GB on having line numbering not disabled for working with very large files.
                  SplitIssues.mac (448 Bytes)   2
                  Macro file for UE v26.00.0.48 with first macro SplitIssues and second macro NextIssueNumber stored in the file
                  Best regards from an UC/UE/UES for Windows user from Austria

                  5
                  NewbieNewbie
                  5

                    Jan 29, 2023#9

                    Thank you so very much for all your time, solutions and detailed steps. The file you provided works fantastic and the step by step/explanations REALLY, REALLY help! Gives me a better understanding of the macro sub process - it's just a bit tricky to figure out the setup process needed for the sub to work correctly.

                    So thank you again. This is great and can share with my work team since it can be modified (small tweaks) to work on similar data string tasks - I'm so super STOKED.

                    Take care and you're fantastic and brilliant.

                    Jen