Tapatalk

Macro to write values sequentially on particular place into file

Macro to write values sequentially on particular place into file

81
Advanced UserAdvanced User
81

    Feb 20, 2016#1

    I need a macro that will put values starting from 1 to required number sequentially (i.e. col# will be col1 then col2 and so on and it will start from col1 in every "<row>...</row>"

    In details, sample 1 will become sample 2.

    Sample 1:

    Code: Select all

    <tabular xml:id="jofi844-tbl-0001" pRights="unknown" eRights="yes">
    <title type="main">TABLE 1 S<sc>ecurity</sc> O<sc>fferings of</sc> U.S. B<sc>usiness</sc> C<sc>orporations</sc> 1950&#x2013;1965</title>
    <table frame="topbot" colsep="0" rowsep="0" pgwide="1">
    <tgroup cols="7">
    <colspec colnum="1" colname="col1" align="left"/>
    <colspec colnum="2" colname="col2" align="left"/>
    <colspec colnum="3" colname="col3" align="left"/>
    <colspec colnum="4" colname="col4" align="left"/>
    <colspec colnum="5" colname="col5" align="left"/>
    <colspec colnum="6" colname="col6" align="left"/>
    <colspec colnum="7" colname="col7" align="left"/>
    <thead><row>
    <entry colname="col#" valign="bottom">Year</entry>
    <entry colname="col#" valign="bottom">Total Corporate Securities Issued<link href="#jofi844-tbl-note-0001"><sup>a</sup></link></entry>
    <entry colname="col#" valign="bottom">Total Common Stock Issued<link href="#jofi844-tbl-note-0002"><sup>b</sup></link></entry>
    <entry colname="col#" valign="bottom">Total Preferred Stock Issued<link href="#jofi844-tbl-note-0002"><sup>c</sup></link></entry>
    <entry colname="col#" valign="bottom">Non-Convertible Preferred Stock Issued<link href="#jofi844-tbl-note-0003"><sup>d</sup></link></entry>
    <entry colname="col#" valign="bottom">Non-Convertible as a Per Cent of Total Corporate Securities</entry>
    <entry colname="col#" valign="bottom">Non-Convertible as a Per Cent of Total Preferred</entry>
    </row></thead>
    <tbody>
    <row>
    <entry colname="col#"/>
    <entry colname="col#"/>
    <entry colname="col#"/>
    <entry colname="col#"/>
    <entry colname="col#"/>
    <entry colname="col#"><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML" altimg="urn:x-wiley:00221082:jofi844:equation:jofi844-math-0001" wiley:location="equation/jofi844-math-0001.png">$\left(\underline {4} \right)$</math></entry>
    <entry colname="col#"><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML" altimg="urn:x-wiley:00221082:jofi844:equation:jofi844-math-0002" wiley:location="equation/jofi844-math-0002.png">$\left(\underline {4} \right)$</math></entry>
    </row>
    <row>
    <entry colname="col#"/>
    <entry colname="col#">(1)</entry>
    <entry colname="col#">(2)</entry>
    <entry colname="col#">(3)</entry>
    <entry colname="col#">(4)</entry>
    <entry colname="col#">(1)</entry>
    <entry colname="col#">(3)</entry>
    </row>
    <row>
    <entry colname="col#">1950</entry>
    <entry colname="col#">&#x0024; 6,361</entry>
    <entry colname="col#">&#x0024; 810</entry>
    <entry colname="col#">&#x0024; 630</entry>
    <entry colname="col#">&#x0024; 409</entry>
    <entry colname="col#">6.4&#x0025;</entry>
    <entry colname="col#">64.9&#x0025;</entry>
    </row>
    <row>
    <entry colname="col#">1951</entry>
    <entry colname="col#">7,741</entry>
    <entry colname="col#">1,216</entry>
    <entry colname="col#">837</entry>
    <entry colname="col#">271</entry>
    <entry colname="col#">3.5</entry>
    <entry colname="col#">32.4</entry>
    </row>
    <row>
    <entry colname="col#">1952</entry>
    <entry colname="col#">9,534</entry>
    <entry colname="col#">1,368</entry>
    <entry colname="col#">564</entry>
    <entry colname="col#">268</entry>
    <entry colname="col#">2.8</entry>
    <entry colname="col#">47.5</entry>
    </row>
    <row>
    <entry colname="col#">1953</entry>
    <entry colname="col#">8,898</entry>
    <entry colname="col#">1,326</entry>
    <entry colname="col#">488</entry>
    <entry colname="col#">382</entry>
    <entry colname="col#">4.3</entry>
    <entry colname="col#">78.3</entry>
    </row>
    <row>
    <entry colname="col#">1954</entry>
    <entry colname="col#">9,516</entry>
    <entry colname="col#">1,213</entry>
    <entry colname="col#">816</entry>
    <entry colname="col#">518</entry>
    <entry colname="col#">5.4</entry>
    <entry colname="col#">63.5</entry>
    </row>
    <row>
    <entry colname="col#">1955</entry>
    <entry colname="col#">10,240</entry>
    <entry colname="col#">2,185</entry>
    <entry colname="col#">635</entry>
    <entry colname="col#">388</entry>
    <entry colname="col#">3.8</entry>
    <entry colname="col#">61.1</entry>
    </row>
    <row>
    <entry colname="col#">1956</entry>
    <entry colname="col#">10,939</entry>
    <entry colname="col#">2,301</entry>
    <entry colname="col#">636</entry>
    <entry colname="col#">319</entry>
    <entry colname="col#">2.9</entry>
    <entry colname="col#">50.2</entry>
    </row>
    <row>
    <entry colname="col#">1957</entry>
    <entry colname="col#">12,884</entry>
    <entry colname="col#">2,516</entry>
    <entry colname="col#">411</entry>
    <entry colname="col#">216</entry>
    <entry colname="col#">1.7</entry>
    <entry colname="col#">52.6</entry>
    </row>
    <row>
    <entry colname="col#">1958</entry>
    <entry colname="col#">11,558</entry>
    <entry colname="col#">1,334</entry>
    <entry colname="col#">571</entry>
    <entry colname="col#">372</entry>
    <entry colname="col#">3.2</entry>
    <entry colname="col#">65.1</entry>
    </row>
    <row>
    <entry colname="col#">1959</entry>
    <entry colname="col#">9,748</entry>
    <entry colname="col#">2,027</entry>
    <entry colname="col#">531</entry>
    <entry colname="col#">238</entry>
    <entry colname="col#">2.4</entry>
    <entry colname="col#">44.8</entry>
    </row>
    <row>
    <entry colname="col#">1960</entry>
    <entry colname="col#">10,154</entry>
    <entry colname="col#">1,664</entry>
    <entry colname="col#">409</entry>
    <entry colname="col#">335</entry>
    <entry colname="col#">3.3</entry>
    <entry colname="col#">81.9</entry>
    </row>
    <row>
    <entry colname="col#">1961</entry>
    <entry colname="col#">13,165</entry>
    <entry colname="col#">3,294</entry>
    <entry colname="col#">449</entry>
    <entry colname="col#">255</entry>
    <entry colname="col#">1.9</entry>
    <entry colname="col#">56.8</entry>
    </row>
    <row>
    <entry colname="col#">1962</entry>
    <entry colname="col#">10,705</entry>
    <entry colname="col#">1,314</entry>
    <entry colname="col#">422</entry>
    <entry colname="col#">202</entry>
    <entry colname="col#">1.9</entry>
    <entry colname="col#">47.9</entry>
    </row>
    <row>
    <entry colname="col#">1963</entry>
    <entry colname="col#">12,237</entry>
    <entry colname="col#">1,022</entry>
    <entry colname="col#">342</entry>
    <entry colname="col#">245</entry>
    <entry colname="col#">2.0</entry>
    <entry colname="col#">71.6</entry>
    </row>
    <row>
    <entry colname="col#">1964</entry>
    <entry colname="col#">13,957</entry>
    <entry colname="col#">2,679</entry>
    <entry colname="col#">412</entry>
    <entry colname="col#">279</entry>
    <entry colname="col#">2.0</entry>
    <entry colname="col#">67.7</entry>
    </row>
    <row>
    <entry colname="col#">1965</entry>
    <entry colname="col#" rowsep="1">15,992</entry>
    <entry colname="col#" rowsep="1">1,547</entry>
    <entry colname="col#" rowsep="1">725</entry>
    <entry colname="col#" rowsep="1">449</entry>
    <entry colname="col#">2.8</entry>
    <entry colname="col#">61.9</entry>
    </row>
    <row>
    <entry colname="col#">Totals</entry>
    <entry colname="col#">&#x0024;173,629</entry>
    <entry colname="col#">&#x0024;27,716</entry>
    <entry colname="col#">&#x0024;8,878</entry>
    <entry colname="col#">&#x0024;5,146</entry>
    <entry colname="col#"/>
    <entry colname="col#"/></row>
    </tbody>
    </tgroup>
    </table>
    <noteGroup xml:id="jofi844-ntgp-0002">
    <note xml:id="jofi844-tbl-note-0001">
    <label>a</label><p>1950&#x2013;1954, <i>Federal Reserve Bulletin</i>., January, 1957, p. 62. 1955&#x2013;1961, <i>Federal Reserve Bulletin</i>., June, 1963, p. 829. 1962&#x2013;1965, <i>Federal Reserve Bulletin</i>., June, 1966, p. 867.</p>
    </note>
    <note xml:id="jofi844-tbl-note-0002">
    <label>b,c</label><p>Estimates of the Securities and Exchange Commission as reported in the <i>Federal Reserve Bulletin</i>., June, 1953, p. 634; December, 1961, p. 1450; April, 1962, p. 446; and June, 1966, p. 867.</p>
    </note>
    <note xml:id="jofi844-tbl-note-0003">
    <label>d</label><p>Refer to Footnote 4.</p>
    </note>
    </noteGroup>
    </tabular>
    Sample 2:

    Code: Select all

    <tabular xml:id="jofi844-tbl-0001" pRights="unknown" eRights="yes">
    <title type="main">TABLE 1 S<sc>ecurity</sc> O<sc>fferings of</sc> U.S. B<sc>usiness</sc> C<sc>orporations</sc> 1950&#x2013;1965</title>
    <table frame="topbot" colsep="0" rowsep="0" pgwide="1">
    <tgroup cols="7">
    <colspec colnum="1" colname="col1" align="left"/>
    <colspec colnum="2" colname="col2" align="left"/>
    <colspec colnum="3" colname="col3" align="left"/>
    <colspec colnum="4" colname="col4" align="left"/>
    <colspec colnum="5" colname="col5" align="left"/>
    <colspec colnum="6" colname="col6" align="left"/>
    <colspec colnum="7" colname="col7" align="left"/>
    <thead><row>
    <entry colname="col1" valign="bottom">Year</entry>
    <entry colname="col2" valign="bottom">Total Corporate Securities Issued<link href="#jofi844-tbl-note-0001"><sup>a</sup></link></entry>
    <entry colname="col3" valign="bottom">Total Common Stock Issued<link href="#jofi844-tbl-note-0002"><sup>b</sup></link></entry>
    <entry colname="col4" valign="bottom">Total Preferred Stock Issued<link href="#jofi844-tbl-note-0002"><sup>c</sup></link></entry>
    <entry colname="col5" valign="bottom">Non-Convertible Preferred Stock Issued<link href="#jofi844-tbl-note-0003"><sup>d</sup></link></entry>
    <entry colname="col6" valign="bottom">Non-Convertible as a Per Cent of Total Corporate Securities</entry>
    <entry colname="col7" valign="bottom">Non-Convertible as a Per Cent of Total Preferred</entry>
    </row></thead>
    <tbody>
    <row>
    <entry colname="col1"/>
    <entry colname="col2"/>
    <entry colname="col3"/>
    <entry colname="col4"/>
    <entry colname="col5"/>
    <entry colname="col6"><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML" altimg="urn:x-wiley:00221082:jofi844:equation:jofi844-math-0001" wiley:location="equation/jofi844-math-0001.png">$\left(\underline {4} \right)$</math></entry>
    <entry colname="col7"><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML" altimg="urn:x-wiley:00221082:jofi844:equation:jofi844-math-0002" wiley:location="equation/jofi844-math-0002.png">$\left(\underline {4} \right)$</math></entry>
    </row>
    <row>
    <entry colname="col1"/>
    <entry colname="col2">(1)</entry>
    <entry colname="col3">(2)</entry>
    <entry colname="col4">(3)</entry>
    <entry colname="col5">(4)</entry>
    <entry colname="col6">(1)</entry>
    <entry colname="col7">(3)</entry>
    </row>
    <row>
    <entry colname="col1">1950</entry>
    <entry colname="col2">&#x0024; 6,361</entry>
    <entry colname="col3">&#x0024; 810</entry>
    <entry colname="col4">&#x0024; 630</entry>
    <entry colname="col5">&#x0024; 409</entry>
    <entry colname="col6">6.4&#x0025;</entry>
    <entry colname="col7">64.9&#x0025;</entry>
    </row>
    <row>
    <entry colname="col1">1951</entry>
    <entry colname="col2">7,741</entry>
    <entry colname="col3">1,216</entry>
    <entry colname="col4">837</entry>
    <entry colname="col5">271</entry>
    <entry colname="col6">3.5</entry>
    <entry colname="col7">32.4</entry>
    </row>
    <row>
    <entry colname="col1">1952</entry>
    <entry colname="col2">9,534</entry>
    <entry colname="col3">1,368</entry>
    <entry colname="col4">564</entry>
    <entry colname="col5">268</entry>
    <entry colname="col6">2.8</entry>
    <entry colname="col7">47.5</entry>
    </row>
    <row>
    <entry colname="col1">1953</entry>
    <entry colname="col2">8,898</entry>
    <entry colname="col3">1,326</entry>
    <entry colname="col4">488</entry>
    <entry colname="col5">382</entry>
    <entry colname="col6">4.3</entry>
    <entry colname="col7">78.3</entry>
    </row>
    <row>
    <entry colname="col1">1954</entry>
    <entry colname="col2">9,516</entry>
    <entry colname="col3">1,213</entry>
    <entry colname="col4">816</entry>
    <entry colname="col5">518</entry>
    <entry colname="col6">5.4</entry>
    <entry colname="col7">63.5</entry>
    </row>
    <row>
    <entry colname="col1">1955</entry>
    <entry colname="col2">10,240</entry>
    <entry colname="col3">2,185</entry>
    <entry colname="col4">635</entry>
    <entry colname="col5">388</entry>
    <entry colname="col6">3.8</entry>
    <entry colname="col7">61.1</entry>
    </row>
    <row>
    <entry colname="col1">1956</entry>
    <entry colname="col2">10,939</entry>
    <entry colname="col3">2,301</entry>
    <entry colname="col4">636</entry>
    <entry colname="col5">319</entry>
    <entry colname="col6">2.9</entry>
    <entry colname="col7">50.2</entry>
    </row>
    <row>
    <entry colname="col1">1957</entry>
    <entry colname="col2">12,884</entry>
    <entry colname="col3">2,516</entry>
    <entry colname="col4">411</entry>
    <entry colname="col5">216</entry>
    <entry colname="col6">1.7</entry>
    <entry colname="col7">52.6</entry>
    </row>
    <row>
    <entry colname="col1">1958</entry>
    <entry colname="col2">11,558</entry>
    <entry colname="col3">1,334</entry>
    <entry colname="col4">571</entry>
    <entry colname="col5">372</entry>
    <entry colname="col6">3.2</entry>
    <entry colname="col7">65.1</entry>
    </row>
    <row>
    <entry colname="col1">1959</entry>
    <entry colname="col2">9,748</entry>
    <entry colname="col3">2,027</entry>
    <entry colname="col4">531</entry>
    <entry colname="col5">238</entry>
    <entry colname="col6">2.4</entry>
    <entry colname="col7">44.8</entry>
    </row>
    <row>
    <entry colname="col1">1960</entry>
    <entry colname="col2">10,154</entry>
    <entry colname="col3">1,664</entry>
    <entry colname="col4">409</entry>
    <entry colname="col5">335</entry>
    <entry colname="col6">3.3</entry>
    <entry colname="col7">81.9</entry>
    </row>
    <row>
    <entry colname="col1">1961</entry>
    <entry colname="col2">13,165</entry>
    <entry colname="col3">3,294</entry>
    <entry colname="col4">449</entry>
    <entry colname="col5">255</entry>
    <entry colname="col6">1.9</entry>
    <entry colname="col7">56.8</entry>
    </row>
    <row>
    <entry colname="col1">1962</entry>
    <entry colname="col2">10,705</entry>
    <entry colname="col3">1,314</entry>
    <entry colname="col4">422</entry>
    <entry colname="col5">202</entry>
    <entry colname="col6">1.9</entry>
    <entry colname="col7">47.9</entry>
    </row>
    <row>
    <entry colname="col1">1963</entry>
    <entry colname="col2">12,237</entry>
    <entry colname="col3">1,022</entry>
    <entry colname="col4">342</entry>
    <entry colname="col5">245</entry>
    <entry colname="col6">2.0</entry>
    <entry colname="col7">71.6</entry>
    </row>
    <row>
    <entry colname="col1">1964</entry>
    <entry colname="col2">13,957</entry>
    <entry colname="col3">2,679</entry>
    <entry colname="col4">412</entry>
    <entry colname="col5">279</entry>
    <entry colname="col6">2.0</entry>
    <entry colname="col7">67.7</entry>
    </row>
    <row>
    <entry colname="col1">1965</entry>
    <entry colname="col2" rowsep="1">15,992</entry>
    <entry colname="col3" rowsep="1">1,547</entry>
    <entry colname="col4" rowsep="1">725</entry>
    <entry colname="col5" rowsep="1">449</entry>
    <entry colname="col6">2.8</entry>
    <entry colname="col7">61.9</entry>
    </row>
    <row>
    <entry colname="col1">Totals</entry>
    <entry colname="col2">&#x0024;173,629</entry>
    <entry colname="col3">&#x0024;27,716</entry>
    <entry colname="col4">&#x0024;8,878</entry>
    <entry colname="col5">&#x0024;5,146</entry>
    <entry colname="col6"/>
    <entry colname="col7"/></row>
    </tbody>
    </tgroup>
    </table>
    <noteGroup xml:id="jofi844-ntgp-0002">
    <note xml:id="jofi844-tbl-note-0001">
    <label>a</label><p>1950&#x2013;1954, <i>Federal Reserve Bulletin</i>., January, 1957, p. 62. 1955&#x2013;1961, <i>Federal Reserve Bulletin</i>., June, 1963, p. 829. 1962&#x2013;1965, <i>Federal Reserve Bulletin</i>., June, 1966, p. 867.</p>
    </note>
    <note xml:id="jofi844-tbl-note-0002">
    <label>b,c</label><p>Estimates of the Securities and Exchange Commission as reported in the <i>Federal Reserve Bulletin</i>., June, 1953, p. 634; December, 1961, p. 1450; April, 1962, p. 446; and June, 1966, p. 867.</p>
    </note>
    <note xml:id="jofi844-tbl-note-0003">
    <label>d</label><p>Refer to Footnote 4.</p>
    </note>
    </noteGroup>
    </tabular>
    I have created a macro which works fine normally but it does not work when I put a loop in it or check on the box saying "run till the end of file".

    Macro code:

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    PerlReOn
    Find RegExp "(?s)<row>.*</row>"
    Copy 
    Open "C:\Users\user\Desktop\tab1.txt"
    Paste 
    Open "C:\Users\user\Desktop\tab1 - Copy.txt"
    Paste 
    Top
    PerlReOn
    Find RegExp "<row>\r\n"
    Replace All ""
    PerlReOn
    Find RegExp "\r\n</row>"
    Replace All ""
    PerlReOn
    Find RegExp "<entry(.*.)</entry>"
    Replace All "col#"
    ColumnModeOn
    SelectToBottom
    StartSelect
    Key Ctrl+END
    ColumnInsertNum 1 1 LeadingZero 
    Key SHIFT
    Key END
    Copy 
    CloseFile NoSave
    Top
    PerlReOn
    Find RegExp "#"
    Paste 
    ColumnModeOff
    EndSelect
    Top
    PerlReOn
    Find RegExp ""col0"
    Replace All ""col"
    PerlReOn
    Find RegExp " ""
    Replace All """
    SelectAll
    StartSelect
    Copy 
    CloseFile NoSave
    Paste 
    

    6,685587
    Grand MasterGrand Master
    6,685587

      Feb 21, 2016#2

      Just following few macro code lines are needed to convert sample 1 to sample 2 using UE v22.20:

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      PerlReOn
      Top
      Loop 0
      Find MatchCase RegExp "(?<=colname="col)#(?:.+\r\n<entry colname="col#)+"
      IfNotFound
      ExitLoop
      EndIf
      ColumnModeOn
      ColumnInsertNum 1 1 
      ColumnModeOff
      EndLoop
      Top
      
      The Perl regular expression Find command selects:

      <entry colname="col#" valign="bottom">Year</entry>
      <entry colname="col#" valign="bottom">Total Corporate Securities Issued<link href="#jofi844-tbl-note-0001"><sup>a</sup></link></entry>
      <entry colname="col#" valign="bottom">Total Common Stock Issued<link href="#jofi844-tbl-note-0002"><sup>b</sup></link></entry>
      <entry colname="col#" valign="bottom">Total Preferred Stock Issued<link href="#jofi844-tbl-note-0002"><sup>c</sup></link></entry>
      <entry colname="col#" valign="bottom">Non-Convertible Preferred Stock Issued<link href="#jofi844-tbl-note-0003"><sup>d</sup></link></entry>
      <entry colname="col#" valign="bottom">Non-Convertible as a Per Cent of Total Corporate Securities</entry>
      <entry colname="col#
      " valign="bottom">Non-Convertible as a Per Cent of Total Preferred</entry>

      By enabling column mode this selection changes to:

      <entry colname="col#" valign="bottom">Year</entry>
      <entry colname="col#" valign="bottom">Total Corporate Securities Issued<link href="#jofi844-tbl-note-0001"><sup>a</sup></link></entry>
      <entry colname="col#" valign="bottom">Total Common Stock Issued<link href="#jofi844-tbl-note-0002"><sup>b</sup></link></entry>
      <entry colname="col#" valign="bottom">Total Preferred Stock Issued<link href="#jofi844-tbl-note-0002"><sup>c</sup></link></entry>
      <entry colname="col#" valign="bottom">Non-Convertible Preferred Stock Issued<link href="#jofi844-tbl-note-0003"><sup>d</sup></link></entry>
      <entry colname="col#" valign="bottom">Non-Convertible as a Per Cent of Total Corporate Securities</entry>
      <entry colname="col#" valign="bottom">Non-Convertible as a Per Cent of Total Preferred</entry>

      Insert Number is executed on this rectangular selection to insert the incremented numbers.

      Those 2 commands are executed in a loop until nothing to modify found anymore.

      As the Perl regular expression engine inside several years older UE v14.10 is not so powerful than those in UE v22.20, the macro above does not work with UE v14.10. Another method must be used to select the column on the lines on which to insert an incrementing number.

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Top
      Loop
      Find MatchCase "<entry colname="col#"
      Replace "<entry colname="col»"
      IfNotFound
      ExitLoop
      EndIf
      Find MatchCase "</row>"
      Find MatchCase Up "col#"
      Replace "col«"
      Find MatchCase Up "col»"
      Key LEFT ARROW
      Find MatchCase Select "col«"
      ColumnModeOn
      ColumnInsertNum 1 1
      ColumnModeOff
      EndLoop
      Top
      
      This macro replaces the first col# in a row block by col» and the last one by col« to make it possible to create the same selection as the Perl regular expression engine with using a non regular expression find with selecting everything from current caret position being at character » up to end of found string being «. That is not so smart as the Perl regular expression find for selecting the block and produces two additional undo records, but the result is the same.

      The second macro for UE v14.10 can be made faster on using 3 UltraEdit regular expression Replace All commands to insert » and «.

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Top
      Find MatchCase RegExp "^(<row>[^r^n^t ]++<entry colname="col^)#"
      Replace All "^1»"
      Find MatchCase RegExp "^(<entry colname="col^)#^("?+</row>^)"
      Replace All "^1«^2"
      Find MatchCase RegExp "^(<entry colname="col^)#^("?+^p</row>^)"
      Replace All "^1«^2"
      Loop
      Find MatchCase "col»"
      IfNotFound
      ExitLoop
      EndIf
      Key LEFT ARROW
      Find MatchCase Select "col«"
      ColumnModeOn
      ColumnInsertNum 1 1
      ColumnModeOff
      EndLoop
      Top
      
      Best regards from an UC/UE/UES for Windows user from Austria

      81
      Advanced UserAdvanced User
      81

        Feb 21, 2016#3

        If there are more than 9 "<entry...>" elements in each/some "<row>...</row>" elements will the below added command do the required removal of the space character after the number?

        After the last "Top" command

        Code: Select all

        PerlReOn
        Find " ""
        Replace All """
        I have tried it and works fine, but just wanted to know whether " "" finds any other things apart from a space + a double quote in Perl regex.

        Also, is it possible to create a macro for the same kind of sample but with added alignments shown in the below sample.

        Code: Select all

        <tabular xml:id="jofi854-tbl-0001" pRights="unknown" eRights="yes">
        <table frame="topbot" colsep="0" rowsep="0" pgwide="1">
        <tgroup cols="7">
        <colspec colnum="1" colname="col1" align="left"/>
        <colspec colnum="2" colname="col2" align="left"/>
        <colspec colnum="3" colname="col3" align="left"/>
        <colspec colnum="4" colname="col4" align="left"/>
        <colspec colnum="5" colname="col5" align="left"/>
        <colspec colnum="6" colname="col6" align="left"/>
        <colspec colnum="7" colname="col7" align="left"/>
        <thead><row>
        <entry colname="col#" valign="bottom">Year</entry>
        <entry colname="col#" valign="bottom">Total Corporate Securities Issued<link href="#jofi844-tbl-note-0001"><sup>a</sup></link></entry>
        <entry colname="col#" valign="bottom">Total Common Stock Issued<link href="#jofi844-tbl-note-0002"><sup>b</sup></link></entry>
        <entry colname="col#" valign="bottom">Total Preferred Stock Issued<link href="#jofi844-tbl-note-0002"><sup>c</sup></link></entry>
        <entry colname="col#" valign="bottom">Non-Convertible Preferred Stock Issued<link href="#jofi844-tbl-note-0003"><sup>d</sup></link></entry>
        <entry colname="col#" valign="bottom">Non-Convertible as a Per Cent of Total Corporate Securities</entry>
        <entry colname="col#" valign="bottom">Non-Convertible as a Per Cent of Total Preferred</entry>
        </row></thead>
        <tbody>
        <row rowsep="3">
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry colname="col#"/>
        <entry align="right" colname="col#"><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML" altimg="urn:x-wiley:00221082:jofi844:equation:jofi844-math-0001" wiley:location="equation/jofi844-math-0001.png">$\left(\underline {4} \right)$</math></entry>
        <entry align="right" colname="col#"><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML" altimg="urn:x-wiley:00221082:jofi844:equation:jofi844-math-0002" wiley:location="equation/jofi844-math-0002.png">$\left(\underline {4} \right)$</math></entry>
        </row>
        <row>
        <entry align="left" colname="col#">1965</entry>
        <entry align="left" colname="col#" rowsep="1">15,992</entry>
        <entry align="left" colname="col#" rowsep="1">1,547</entry>
        <entry align="center" colname="col#" rowsep="1">725</entry>
        <entry align="center" colname="col#" rowsep="1">449</entry>
        <entry align="char" char="." colname="col#">2.8</entry>
        <entry align="char" char="." colname="col#">61.9</entry>
        </row>
        <row>
        <entry align="center" colname="col#">1965</entry>
        <entry align="center" colname="col#" rowsep="1">15,992</entry>
        <entry align="center" colname="col#" rowsep="1">1,547</entry>
        <entry align="center" colname="col#" rowsep="1">725</entry>
        <entry align="center" colname="col#" rowsep="1">449</entry>
        <entry align="center" colname="col#">2.8</entry>
        <entry align="center" colname="col#">61.9</entry>
        </row>
        <row>
        <entry align="left" colname="col#">Totals</entry>
        <entry align="char" char="." colname="col#">&#x0024;173.629</entry>
        <entry align="char" char="." colname="col#">&#x0024;27.716</entry>
        <entry align="char" char="." colname="col#">&#x0024;8.878</entry>
        <entry align="char" char="." colname="col#">&#x0024;5.146</entry>
        <entry colname="col#"/>
        <entry colname="col#"/></row>
        </tbody>
        </tgroup>
        </table>
        </tabular>

        6,685587
        Grand MasterGrand Master
        6,685587

          Feb 21, 2016#4

          Well, the non regular expression replace all with search string " "" and replace string """ removes EVERYWHERE in file a space character left to a double quote.

          It would be most likely better to use this UltraEdit tagged regular expression Replace All

          Code: Select all

          UnixReOff
          Find MatchCase RegExp "^(colname="col[0-9]+^) +"
          Replace All "^1"
          
          Or use alternatively this Perl regular expression using back-references Replace All

          Code: Select all

          PerlReOn
          Find MatchCase RegExp "(colname="col[0-9]+) +"
          Replace All "\1"
          
          Both make sure to remove the space(s) after the column number in value of attribute colname.

          For your second task with inserting incrementing numbers on not aligned colname I first want to offer a script solution as I would use nowadays for such tasks.

          Code: Select all

          if (UltraEdit.document.length > 0)  // Is any file opened?
          {
             // Define environment for this script.
             UltraEdit.insertMode();
             if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
             else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
          
             // Move caret to top of the active file.
             UltraEdit.activeDocument.top();
          
             // Select entire file.
             UltraEdit.activeDocument.selectAll();
          
             // Is something selected, i.e. is file not empty?
             if (UltraEdit.activeDocument.isSel())
             {
                // Load (nearly) entire file content into memory into an array of strings
                // split into blocks whereby end tag </row> defines where to split.
                var asRowBlocks = UltraEdit.activeDocument.selection.split("</row>");
          
                // Process each block with the exception of last block as the
                // last block surely never contains entry elements to process.
                var nBlockCount = asRowBlocks.length - 1;
                for (var nBlock = 0; nBlock < nBlockCount; nBlock++)
                {
                   // Split each row block into entry blocks using start tag <entry
                   // as separator. The first block does surely not contain an col#
                   // value and therefore can be always skipped on next processing
                   // which replaces "col#" in each entry block by "col" and the
                   // appropriate column number.
                   var asEntries = asRowBlocks[nBlock].split("<entry");
                   for (var nEntry = 1; nEntry < asEntries.length; nEntry++)
                   {
                      asEntries[nEntry] = asEntries[nEntry].replace("col#","col"+nEntry.toString(10));
                   }
                   // Join the updated entry blocks together to a row block.
                   asRowBlocks[nBlock] = asEntries.join("<entry");
                }
                // Join all updated row blocks together to entire file content
                // and overwrite everything still selecting in active file.
                UltraEdit.activeDocument.write(asRowBlocks.join("</row>"));
                UltraEdit.activeDocument.top();
             }
          }
          
          I used this method in splitting up a file into blocks one or more times for inserting incrementing numbers already several times. It is really easy to code and very fast as everything is done in memory. The big advantages in comparison to macro solution below are:
          • It does not matter if other lines than lines with entry element exist within a row element.
          • It does not even matter if multiple entry elements are on the same line.
          But this method can't be used for Unicode encoded files with characters having a code value greater U+00FF or for very large files. But this is most often no problem.

          But here is also a macro solution using only non regexp and UltraEdit regexp replaces for compatibility with UE v14.10.

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          UltraEditReOn
          Top
          TrimTrailingSpaces
          Find MatchCase "></row>"
          Replace All ">^p</row>"
          Find MatchCase RegExp "^(<row?++>^)<"
          Replace All "^1^p<"
          Find MatchCase RegExp "%^(<entry*colname="^)^(col#^)"
          Replace All "^2^1"
          Find MatchCase RegExp "^(<row*>^pcol^)#"
          Replace All "^1»"
          Find MatchCase RegExp "%col#^(?+^p</row>^)"
          Replace All "col«^1"
          Loop 0
          Find MatchCase "col»"
          IfNotFound
          ExitLoop
          EndIf
          Key LEFT ARROW
          Find MatchCase Select "col«"
          ColumnModeOn
          ColumnInsertNum 1 1
          ColumnModeOff
          EndLoop
          Top
          Find MatchCase RegExp "%^(col[0-9]+^) ++^(<entry*colname="^)"
          Replace All "^2^1"
          
          The first 2 Replace All commands make more or less sure that each start row tag is at end of a line and each end row tag is at start of a line because for some unknown reason the last end row tag in your examples is always on same line as last entry line. (Well, I suppose the reason is a Replace All searching for </row><row> and using </row>^p<row> as replace string which of course does not move last </row> to a new line.)

          The third UE regexp Replace All moves all col# to start of the line to get them aligned in the file for inserting the number.

          The fourth and fifth UE regexp Replace All replace first col# in line below start row tag by col» and last col# in line above end row tag by col«.

          Then the loop is executed finding » and «, selecting the column containing the 2 characters, and inserting the incremented numbers.

          Finally one more UE regexp Replace All is used to move all colX from start of the line back to original position in line and additionally remove also the unwanted space(s) after the inserted number as not being included in both tags (marking/capturing groups).
          Best regards from an UC/UE/UES for Windows user from Austria