Best method to bring all iterations of a string to the same column

Best method to bring all iterations of a string to the same column

711
Advanced UserAdvanced User
711

    6:49 - Jul 29#1

    What is the best way to achieve this?
    Javascript?
    Too complicated for a Macro?
    Another method?
    I want to 
    (00) Go HOME/Take cursor home/Macro = Key HOME
    (01) Find a string (this is a variable which would be an input to the script/process)
    (02) Note the column where that first iteration of string starts
    (03) Save that Column e.g. to a variable Variable Int-Column_Count
    (04) Find next iteration of the string
    (05) Note the column where this 2nd iteration of string starts
    (06) If Column noted in 5 (2nd iteration) is greater then Int-Column_Count (first iteration)
         Then
          Update Int-Column_Count with this greater number
    (07) Repeat Steps (5) and (6) until ther end of the file
    (08) Go HOME/Take cursor home/Macro = Key HOME
    (09) Find first iteration of string again
    (10) Hit SPACEBAR until the string starts at column Int-Column_Count
    (11) Find next iteration of string
    (12) Repeat (10) and (11) until the end of the file

    Assumptions
    A01 There is only one iteration of string in every line

    Example
    String = "_M"

    File Before (Line 1 String is furthest to RHS)

    Code: Select all

    10.10.96.0           _M24   10.10.96.254   0  A C  ae1.3
    10.10.96.254 _M32           0.0.0.0        0  A H
    10.10.97.128     _M30       10.10.97.130   0  A C  ae1.51
    10.10.97.130  _M32          0.0.0.0        0  A H
    10.10.97.132        _M30    10.10.97.134   0  A C  ae1.91
    File After

    Code: Select all

    10.10.96.0           _M24   10.10.96.254   0  A C  ae1.3
    10.10.96.254         _M32           0.0.0.0        0  A H
    10.10.97.128         _M30       10.10.97.130   0  A C  ae1.51
    10.10.97.130         _M32          0.0.0.0        0  A H
    10.10.97.132         _M30    10.10.97.134   0  A C  ae1.91
    

    6,672577
    Grand MasterGrand Master
    6,672577

      8:17 - Jul 29#2

      I suggest running first a Perl regular expression replace all from top of the file with searching for (?:  +|\t[\t ]*| (?=_M)) and use as replace string \t for converting the file to a tab separated values file. That produces for the provided input example already a well aligned data file if the tab stop value is configured with 8.

      There can be next clicked in traditional menu Column on the menu item Convert to fixed column or on ribbon tab Edit in fourth group Column / block on the down arrow right to item CSV convert and in opened popup menu on item Convert to fixed-width or in contemporary menu Edit in submenu CSV convert on menu item Convert to fixed-width for opening the Convert to Fixed Columns dialog window.

      In this dialog window set the options as follows:
      • Scan first line only (vs. complete file) … unchecked
      • Keep delimiter with fixed columns … unchecked
      • Ignore separator in quotes (')… checked
      • Ignore separator in double quotes (")… checked
      • Separator character (^t for tab): ^t
      Press the button Scan and increase all field widths with exception of last field width by three for three spaces between the data columns. For the example the field widths would be: 15, 7, 15, 4, 6, 6
      Then click on button Convert and execute perhaps additionally Trim trailing spaces.
      The result for the example file is:

      Code: Select all

      10.10.96.0     _M24   10.10.96.254   0   A C   ae1.3
      10.10.96.254   _M32   0.0.0.0        0   A H
      10.10.97.128   _M30   10.10.97.130   0   A C   ae1.51
      10.10.97.130   _M32   0.0.0.0        0   A H
      10.10.97.132   _M30   10.10.97.134   0   A C   ae1.91
      If that reformatting must be done from time to time or even frequently and you want to do all with the execution of an UltraEdit script, see: Converting CSV data to fixed width data? That script is the replacement for the command Convert to fixed column which is not available as scripting command. The additional Perl regular expression replace all can be added easily to this script.
      Best regards from an UC/UE/UES for Windows user from Austria

      711
      Advanced UserAdvanced User
      711

        21:23 - Jul 29#3

        Thanks Mofi. I will absorb...
        Much appreciated