Inserting an incrementing number on every line of a block

Inserting an incrementing number on every line of a block

2
NewbieNewbie
2

    Sep 08, 2009#1

    I am very new to UltraEdit and though I have read the examples and post on incrementing by 1, I still need some help. The following is an example of my file and what I want it to look like. These files have hundreds of lines.

    Code: Select all

    ADD FRDCIVL/UBA-CVL_WRK
    ADD FRDCIVL/UMA-CVL_WRK
    ADD FRDELEC/UBA-ELC_WRK
    ADD FRDELEC/UMA-ELC_WRK
    ADD FRDHVAC/UBA-HVC_WRK
    ADD FRDHVAC/UMA-HVC_WRK
    ADD FRDMISC/UBA-MSC_WRK
    What I need is:

    Code: Select all

    ADD FRDCIVL/UBA-CVL_WRK 50
    ADD FRDCIVL/UMA-CVL_WRK 51
    ADD FRDELEC/UBA-ELC_WRK 52
    ADD FRDELEC/UMA-ELC_WRK 53
    ADD FRDHVAC/UBA-HVC_WRK 54
    ADD FRDHVAC/UMA-HVC_WRK 55
    ADD FRDMISC/UBA-MSC_WRK 56
    ... and so on.
    Any help would be appreciated.

    I am running Xp SP2 and UltraEdit-32

    6,675585
    Grand MasterGrand Master
    6,675585

      Sep 09, 2009#2

      Your lines have the same length. So you don't need a macro for inserting an incrementing number.
      • Just enable Column - Column Mode (hotkey Alt+C),
      • set the cursor at end of the first line and press SPACE,
      • hold SHIFT and use the keys PAGE DOWN and/or DOWN ARROW to select this column on the lines where an incrementing number should be appended,
      • execute Column - Insert Number with First Number set to 50,
      • turn off column mode editing by clicking again on Column - Column Mode or using Alt+C.
      Best regards from an UC/UE/UES for Windows user from Austria

      344
      MasterMaster
      344

        Sep 09, 2009#3

        Just a small addition:
        If the lines were NOT all in the same length, do what Mofi said at the rightmost position you want and then do a regular perl regular expression replace:

        Code: Select all

        [ \t]+([0-9]+)
        with:

        Code: Select all

         $1
        (blank dollar one)

        This kicks off all spaces/tabs before the numbers except one space, assuming you dont have a blank followed by a number at the beginning of a line.

        rds Bego
        Normally using all newest english version incl. each hotfix. Win 10 64 bit

        2
        NewbieNewbie
        2

          Sep 09, 2009#4

          Thanks Mofi but my file has different length lines. Bego, I am not sure where/how to run the perl-expression replace. Do I run this after doing what Mofi suggested and is this done at a dos command line or what?

          6,675585
          Grand MasterGrand Master
          6,675585

            Sep 09, 2009#5

            Normally different lengths of the lines is no problem if nothing is on right side of the column where a number should be inserted in a block. For example if you have something like this (from a resource file):

            Code: Select all

            #define IDB_OUT_DISABLED     |
            #define IDB_OUT_ENABLED
            #define IDC_CHANGED_CURSOR
            #define IDC_CURVES_CURSOR
            #define IDI_BB_EVENTLIST
            #define IDR_VC
            #define IDD_ABOUTBOX
            #define IDD_ALREADYPERMITTED
            #define IDD_BB_SLAVE_MISSING
            #define IDD_CALIBRATE
            All to do is set the cursor in the first line to column + 1 of the longest line. In the example above this position is marked with | which is column 30 as indicated in the status bar at bottom of the UltraEdit window.

            Now enable the column mode, hold SHIFT and select the lines in this column with the cursor keys. You can use also the mouse. Then run Column - Insert Column. With 2000 as First Number you get now:

            Code: Select all

            #define IDB_OUT_DISABLED     2000
            #define IDB_OUT_ENABLED      2001
            #define IDC_CHANGED_CURSOR   2002
            #define IDC_CURVES_CURSOR    2003
            #define IDI_BB_EVENTLIST     2004
            #define IDR_VC               2005
            #define IDD_ABOUTBOX         2006
            #define IDD_ALREADYPERMITTED 2007
            #define IDD_BB_SLAVE_MISSING 2008
            #define IDD_CALIBRATE        2009
            Turn off the column mode. If the multiple spaces are no problem, you are finished. If you want to get this

            Code: Select all

            #define IDB_OUT_DISABLED 2000
            #define IDB_OUT_ENABLED 2001
            #define IDC_CHANGED_CURSOR 2002
            #define IDC_CURVES_CURSOR 2003
            #define IDI_BB_EVENTLIST 2004
            #define IDR_VC 2005
            #define IDD_ABOUTBOX 2006
            #define IDD_ALREADYPERMITTED 2007
            #define IDD_BB_SLAVE_MISSING 2008
            #define IDD_CALIBRATE 2009
            set the cursor to start of the first line or select the block. Next press Ctrl+R to open the replace dialog. Enable the option Regular Expressions. If the regular expression engine is Perl or Unix search for "[ \t]+([0-9]+)$" and replace it with " \1" in the current file or only the selected text using button Replace All. If the regexp engine is UltraEdit, search for "[ \t]+^([0-9]+)^$" and use " ^1" as replace string. The search and replace strings you have to copy are without the double quotes! The preceding single space in the replace string is important.

              Mar 03, 2010#6

              I want to write here some words about an enhancement in UE v16.00.0.1025 in comparison to previous versions not mentioned anywhere else.

              On 28 Feb. 2006 (4 years ago) I sent IDM an email with a request for an enhancement for supporting entering the First Number and also the Increment value at the Insert Number dialog also in hexadecimal which would be very helpful when inserting the numbers also hexadecimal. Obviously enough other users requested the same and therefore after 4 years I could see in the email to the beta testers that this feature was implemented now in UE v16.00. But it was still too restricted for me. In beta version the entered strings were interpreted always hexadecimal if option Hexadecimal was selected, and decimal if option Decimal was selected. So I sent IDM my static C++ function GetNumberFromString which I have written for one of our applications and the IDM developers obviously used that function with some modifications. (My function returns error codes when anything in the string is not valid for a number string, the function used now by IDM simply removes everything left or right an invalid character and converts the remaining part of the number string.

              The long and the short of it is that you are free now to enter a number decimal or hexadecimal independent on the format option for inserting the numbers based on following rules (in this order):
              1. 0x or 0X (anywhere) in the entered string (typically at start) results always in interpreting the entered number as hexadecimal. 0x62 is therefore decimal 98. The number is always converted to a signed 32-bit number. So 0xFFFFFFFF is decimal -1. Everything left 0x or 0X is deleted from the entered string before conversion to an integer. So -0x5A is interpreted as 0x5A. An invalid character for a hexadecimal string and everything right of it is also deleted before conversion to integer, for example 0x5as3 is interpreted as 0x5a.
              2. - or + inside the string (typcially as first character) results in interpreting the rest of the string as decimal character. Everything left the sign character is deleted from the string before conversion. A non digit character and everything right of this character is also removed from the string before conversion. For example 35+70q4 is interpreted as +70.
              3. If the string contains [A-Fa-f], it is also automatically interpreted as hexadecimal number. Negative numbers in hexadecimal format must be entered using [89A-Fa-f][0-9A-Fa-f]{7,7}. It is not possible to write for example -5A.
              4. Numbers containing only digits are interpreted as decimal numbers. A non digit character and everything right of it is removed from the string before converting the rest of string to an integer number.
              In other words you can enter decimal 32 also as 0x20, or decimal -5 as FFFFFFFB or 0XFFFFFFFB.
              Best regards from an UC/UE/UES for Windows user from Austria