Inserting a line after every 10.000 lines

Inserting a line after every 10.000 lines

1
NewbieNewbie
1

    Jul 05, 2007#1

    Hi

    I've never used the macro facility yet. What I need to do is insert a commit line after every 10,000 records. The macro I have so far is as follows.

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff

    Loop
    GotoLine 10000 1
    "commit;
    "

    EndLoop


    So this works for the first insert at line 10,000, now how do I go through the rest of the file and then add a commit at 20,000, 30,000 until I reach the end of file?

    6,604548
    Grand MasterGrand Master
    6,604548

      Jul 06, 2007#2

      You have not written which version of UltraEdit you use. That job could be easily done with a script which supports variables and mathematical operations to increases the line number always by 10.000 until end of file is reached.

      To do this with a macro a complete different approach must be used which of course is very slow and needs 2 macros because nesting of loops is not possible.

      But before I post this macro solution a question: Is your file with fixed columns which means have all lines the same length (= number of characters)?

      If this is true, you can use the function File - Special Functions - Insert String at Every Increment to insert commit;^p after every x bytes.

      If it is not a fixed column width file and trailing spaces are not important you can temporarily convert the file to a fixed column width file. Click on Column - Convert to Fixed Column, enter as Separator Character a character which surely does not exist in your file and enter at Field Widths only 1 value which is surely greater than the longest line in your file. Then press the button Convert.

      Now after UltraEdit has inserted trailing spaces at every line to get same length for every line you can use the function Insert String at Every Increment. 1 line has the entered width + 2 bytes (CR and LF). So you can easily calculate the number of bytes for 10.000 lines.

      After inserting the string use Format - Trim Trailing Spaces to delete all the inserted spaces which are not needed anymore.
      Best regards from an UC/UE/UES for Windows user from Austria

      262
      MasterMaster
      262

        Jul 06, 2007#3

        Just to prove Mofis point that a script are the right choice for this task, consider this:

        Code: Select all

        var LINEENDING = "\r\n"; /* Adjust to "\n" only for Unix files */
        var stepLines = 10000;   /* Number of lines to jump forward */
        var gotoLine = stepLines + 1; /* First stop. +1 is for the extra inserted line */
        
        UltraEdit.activeDocument.top(); /* From the top */
        
        while (! UltraEdit.activeDocument.isEof()) {
           UltraEdit.activeDocument.gotoLine(gotoLine,0);
           gotoLine = UltraEdit.activeDocument.currentLineNum + stepLines + 1; /* make ready for next jump */
        
           var ColNum = UltraEdit.activeDocument.currentColumnNum;
           if (typeof(UltraEdit.activeDocumentIdx) == "undefined") ColNum++;
           if (ColNum>1) {
              UltraEdit.activeDocument.write(LINEENDING); /* if last line of the file doesn't end with line endings */
           }
        
           UltraEdit.activeDocument.write("commit;"+LINEENDING);
        }
        This will of course only work for UE13.10 users and above, so if you use earlier versions then go with Mofis suggestions or restate your need for a macro and at the same time tell us your UE version.