Tapatalk

Update default values in file 1 with values in file 2

Update default values in file 1 with values in file 2

2
NewbieNewbie
2

    Mar 18, 2008#1

    I'm not sure if this is possible with UltraEdit.

    I have two files, a program file and a parameter file. In the program files there are default parameter values, in the parameter file there are true parameter values.
    My question is, is it possible to replace the default parameter vaules with the parameter value in the second file?
    example.

    file 1 (program file):

    Code: Select all

    BEGIN DSJOB
       Identifier "defaultvalue1"
       DateModified "2008-02-22"
       TimeModified "08.52.00"
       BEGIN DSRECORD
          Identifier "ROOT"
          OLEType "CJobDefn"
          Readonly "0"
          Name "defaultvalue1"
          Description "Interface Data: Bepalen controlegetallen van de ingelezen interface."
          NextID "2"
          Container "V0"
          FullDescription =+=+=+=
    
          JobVersion "36.0.0"
          ControlAfterSubr "0"
          Parameters "CParameters"
          BEGIN DSSUBRECORD
             Name defaultvalue1
             Prompt "defaultvalue2"
             ParamType "defaultvalue3"
             ParamLength "defaultvalue4"
             ParamScale "defaultvalue5"
          END DSSUBRECORD
    Same file again without the preceding characters, but with bold highlighting the important values which should be replaced.

    BEGIN DSJOB
    Identifier "defaultvalue1"
    DateModified "2008-02-22"
    TimeModified "08.52.00"
    BEGIN DSRECORD
    Identifier "ROOT"
    OLEType "CJobDefn"
    Readonly "0"
    Name "defaultvalue1"
    Description "Interface Data: Bepalen controlegetallen van de ingelezen interface."
    NextID "2"
    Container "V0"
    FullDescription =+=+=+=

    JobVersion "36.0.0"
    ControlAfterSubr "0"
    Parameters "CParameters"
    BEGIN DSSUBRECORD
    Name defaultvalue1
    Prompt "defaultvalue2"
    ParamType "defaultvalue3"
    ParamLength "defaultvalue4"
    ParamScale "defaultvalue5"
    END DSSUBRECORD

    file2 parameter file: (has no preceding white-spaces)
    defaultvalue1 = interface1
    defaultvalue2 = testting
    defaultvalue3 = 0
    defaultvalue4 = 0
    defaultvalue5 = 0

    The program file is not a large files approximatly 2 MB, parameter file is less, approximatly 500 KB.
    Version of UE is V10.20c
    I am new to this forum and writing macros as well :)

    If you know how to write the macro, then please help me.

    6,685587
    Grand MasterGrand Master
    6,685587

      Mar 19, 2008#2

      Yes, this is possible with a macro. I guess there are more such blocks in both files and because defaultvalue1 must be replaced 3 times per block a really general search and replace method cannot be used. The following works according to your examples. If you need an explanation, I can write it at weekend.

      By the way: Is the second Name defaultvalue1 really with double quotes? The macro currently expects that.

      The macro property Continue if a Find with Replace not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Bottom
      IfColNum 1
      Else
      "
      "
      EndIf
      Top
      TrimTrailingSpaces
      Loop
      Find "^p^p"
      Replace All "^p"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Find RegExp "%*= "
      Replace All ""
      SelectAll
      Clipboard 9
      Copy
      CloseFile NoSave
      Top
      Paste
      "#"
      Loop
      Top
      IfCharIs "#"
      Delete
      ExitLoop
      EndIf
      StartSelect
      Key END
      Copy
      EndSelect
      DeleteLine
      Find "Identifier "defaultvalue1""
      Replace "Identifier "^c""
      Find "Name "defaultvalue1""
      Replace "Name "^c""
      Find "Name defaultvalue1"
      Replace "Name ^c"
      Top
      StartSelect
      Key END
      Copy
      EndSelect
      DeleteLine
      Find "Prompt "defaultvalue2""
      Replace "Prompt "^c""
      Top
      StartSelect
      Key END
      Copy
      EndSelect
      DeleteLine
      Find "ParamType "defaultvalue3""
      Replace "ParamType "^c""
      Top
      StartSelect
      Key END
      Copy
      EndSelect
      DeleteLine
      Find "ParamLength "defaultvalue4""
      Replace "ParamLength "^c""
      Top
      StartSelect
      Key END
      Copy
      EndSelect
      DeleteLine
      Find "ParamScale "defaultvalue5""
      Replace "ParamScale "^c""
      EndLoop
      ClearClipboard
      Clipboard 0
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Mar 27, 2008#3

        Dear Mofi,

        Thank you so much for the example.
        If you can make a explanation i will appreciate it.

        Regards,


        Cemmie

        6,685587
        Grand MasterGrand Master
        6,685587

          Mar 30, 2008#4

          Here is the macro code again with comments (lines starting with //) and indenting. It can be best read saving it into a file with the extension UEM and using the syntax highlighting for UE Macro source code files. For details see my sticky Macro examples and reference for beginners and experts topic.

          Code: Select all

              InsertMode
              ColumnModeOff
              HexOff
              UnixReOff
          //  Make sure the last line of the parameter file has a line termination.
              Bottom
              IfColNum 1
              Else
                  "
                  "
              EndIf
              Top
          //  Delete all spaces and tabs at end of every line and all blank lines.
              TrimTrailingSpaces
              Loop
                  Find "^p^p"
                  Replace All "^p"
                  IfNotFound
                      ExitLoop
                  EndIf
              EndLoop
          //  Delete at every line everything before equal sign and the following space.
          //  Now only the values which should be inserted into the other file remain.
              Find RegExp "%*= "
              Replace All ""
          //  Copy this parameter list into user clipboard 9 and close the paramter file
          //  without saving the changes. The program file get automatically the focus.
              SelectAll
              Clipboard 9
              Copy
              CloseFile NoSave
          //  At top of the program file insert the parameter list and additionally the
          //  character # below at start of the first line in the program file. It is
          //  required that there is no value in the parameter list which starts with #.
              Top
              Paste
              "#"
          //  Run the following loop until character # is found at start of the line
          //  respectively at top of the file. If found, delete this inserted character
          //  and exit the loop.
              Loop
                  Top
                  IfCharIs "#"
                      Delete
                      ExitLoop
                  EndIf
          //  Select the first parameter value (from defaultvalue1 of current block),
          //  copy it to user clipboard 9 and delete whole line.
                  StartSelect
                  Key END
                  Copy
                  EndSelect
                  DeleteLine
          //  Search for first occurrence of the string below and replace string
          //  "defaultvalue1" with the parameter value in ative clipboard.
                  Find "Identifier "defaultvalue1""
                  Replace "Identifier "^c""
          //  Make the same single replace for the other 2 occurences of "defaultvalue1"
          //  in the current section.
                  Find "Name "defaultvalue1""
                  Replace "Name "^c""
                  Find "Name defaultvalue1"
                  Replace "Name ^c"
          //  Make the single replace with the same method for the other 4 parameter
          //  values. The only difference is that they exist only once per section.
                  Top
                  StartSelect
                  Key END
                  Copy
                  EndSelect
                  DeleteLine
                  Find "Prompt "defaultvalue2""
                  Replace "Prompt "^c""
                  Top
                  StartSelect
                  Key END
                  Copy
                  EndSelect
                  DeleteLine
                  Find "ParamType "defaultvalue3""
                  Replace "ParamType "^c""
                  Top
                  StartSelect
                  Key END
                  Copy
                  EndSelect
                  DeleteLine
                  Find "ParamLength "defaultvalue4""
                  Replace "ParamLength "^c""
                  Top
                  StartSelect
                  Key END
                  Copy
                  EndSelect
                  DeleteLine
                  Find "ParamScale "defaultvalue5""
                  Replace "ParamScale "^c""
          //  At this point the 5 parameter values have replaced the templates
          //  in the first section where "defaultvalue1" was still found. Continue
          //  now the the next 5 parameter values in the next section.
              EndLoop
          //  At the end after processing all parameter values clear user clipboard 9
          //  to free RAM and switch back to the standard Windows clipboard.
              ClearClipboard
              Clipboard 0
          Best regards from an UC/UE/UES for Windows user from Austria