replacing variables with values

replacing variables with values

5
NewbieNewbie
5

    Mar 09, 2006#1

    Hi,

    I have a text file which contains variables in the form of:

    <ipaddress1> <ipaddress2>
    interface <ipaddress1>


    In the beginning of the file, their is a section where these variables
    can be defined, like:

    ====================
    <ipaddress1>=<10.1.1.1>
    <ipaddress2>=<10.1.1.2>
    ====================

    I would like to write a macro who looks for these definition,
    then extracts the values using RegExpression matching
    and then replaces all occurrences of <ipaddress1> with 10.1.1.1
    and <ipaddress2> with 10.1.1.2 in the whole document.

    Any help to get me on my way is appreciated...

    Geert

    6,675585
    Grand MasterGrand Master
    6,675585

      Mar 10, 2006#2

      That's not difficult for me because I have already written some macros for personal use which uses the same technique. Here is the macro according to your example. Make sure - manually or with the macro - that the cursor is set at start of the line with the first variable.

      How it works:

      The loop needed will exit if the first character of the line is a = because of the line ==================== after your variables. You can use also an other character if the === line does not really exist in your file or use instead of IfCharIs "=" the following code sequence:

      IfCharIs "<"
      Else


      This alternate version will exit the loop, if the first character of the line is not a <.

      Inside the loop the variable name <ipaddress1> will be selected and copied to user clipboard 9.

      Next it sets the cursor 2 positions to right and selects 10.1.1.1.

      Then it runs a replace all with the search string is the content of the clipboard and the replace string is the current selection.

      After replace all which does not modify current cursor position it goes to start of next line and if this line does not start with = it will continue.

      I'm busy at the moment so I have not inserted extra code for error handling.

      And don't forget to enable the macro property Continue if a Find with Replace not found.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Clipboard 9
      Loop
      IfCharIs "="
      ExitLoop
      EndIf
      StartSelect
      Find Select ">"
      Copy
      EndSelect
      Key RIGHT ARROW
      Key RIGHT ARROW
      StartSelect
      Find Select ">"
      Key LEFT ARROW
      Find MatchCase "^c"
      Replace All "^s"
      EndSelect
      Key HOME
      Key DOWN ARROW
      EndLoop
      ClearClipboard
      Clipboard 0
      Best regards from an UC/UE/UES for Windows user from Austria