Need to insert a string every 1000 lines

Need to insert a string every 1000 lines

2

    Feb 11, 2009#1

    Sorry if this is in the wrong spot I don't know if this should be a macro, script, etc. I am new to UltraEdit.

    Anyhow I have a bunch of SQL code and I need to insert a "GO" every 1000 lines to the end of the file how would I go about this? I have 6 files about 200,000 rows each.

    236
    MasterMaster
    236

      Feb 12, 2009#2

      I'm assuming you have UE V14. In theory, this Perl regex should work. In practice, this might depend on the size of the file and the length of the lines. Try the following on a backup copy first:

      Make sure the cursor is at the top of the file.
      Open the Replace dialog, select Perl regular expressions and enter

      ((?:.*\r\n){1000})

      in the search box and

      \1GO\r\n

      in the replace box. Then click on "Replace all".

      If that doesn't work, you could also use a macro that simply simulates a "Down Arrow" keystroke 1000 times and then enters "GO<enter>", looping until the end of file. But that will be a lot slower, especially if you have to add checks that you haven't yet reached EOF. So try the above regex first.

      2

        Feb 17, 2009#3

        I couldn't get the regex replace to work. Maybe I was just not doing it right. However, I started to write a JS. Here is what I have. It works, but I have to figure out how to tell how may lines the current document has.

        Code: Select all

        UltraEdit.activeDocument.top();
        
        // current document length set to 27 need to set it to a proper function for length. Or do I need it at all???
        var num = 27;
        for (lineNum = 10; lineNum < num; lineNum += 1000) 
        {
        	UltraEdit.activeDocument.gotoLine(lineNum);
        //UltraEdit.activeDocument.top();
        UltraEdit.activeDocument.write("GO\r\n");
        }
        
        UltraEdit.outputWindow.write("Script Compleated")

        6,682583
        Grand MasterGrand Master
        6,682583

          Feb 21, 2009#4

          What about following script:

          Code: Select all

          UltraEdit.activeDocument.bottom();
          /* Verify if the last line of the copied text also has a line ending.
             If this is not the case insert one and make sure that the auto
             indent feature has not added additional preceding white-spaces. */
          if (UltraEdit.activeDocument.isColNumGt(1)) {
             UltraEdit.activeDocument.insertLine();
             if (UltraEdit.activeDocument.isColNumGt(1)) {
                UltraEdit.activeDocument.deleteToStartOfLine();
             }
          }
          var nInsertCount = Math.floor(UltraEdit.activeDocument.currentLineNum / 1000);
          var nActLineNumber = 0;
          while (nInsertCount--) {
             nActLineNumber += 1001;
             UltraEdit.activeDocument.gotoLine(nActLineNumber,1);
             UltraEdit.activeDocument.write("GO\r\n");
          }
          Best regards from an UC/UE/UES for Windows user from Austria