Vbscript to Compare 2 files which has TNS names and append only the new entry RRS feed

  • Question

  • Hi, i need a VBscript to compare 2 files (source and destination files)  and append the non existing entry in the destination folder. 

    source - which has TNSnames.ora in a particular location and the destination file which has TNSnames.ora. in the local machine. compare both and append the new or non existing entry in the destination folder

    • Edited by spreeths Thursday, September 7, 2017 4:50 AM
    • Moved by Bill_Stewart Tuesday, November 7, 2017 9:23 PM This is not support forum for third party software
    Thursday, September 7, 2017 4:48 AM

All replies

  • Thursday, September 7, 2017 4:56 AM
  • i have written a code it is not comparing rather it is just appending the data

    Dim arrFileLines()
    CONST ForReading = 1
    CONST ForWriting = 2
    CONST ForAppending = 8
    i = 0
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFileSrc = objFSO.OpenTextFile("c:\windows\calltns.txt", ForReading)
    If objFSO.FileExists("c:\windows\tnsnames.ora") Then
    objFSO.CopyFile "c:\windows\tnsnames.ora", "c:\windows\tnsnames.bak", True
    End If
    Set objFileDst = objFSO.OpenTextFile("c:\windows\tnsnames.ora", ForAppending, True)
    Do Until objFileSrc.AtEndOfStream
    Redim Preserve arrFileLines(i)
    arrFileLines(i) = objFileSrc.ReadLine
    i = i + 1
    For l = LBound(arrFileLines) to Ubound(arrFileLines) 
    ' take out to Step -1
    objFileDst.WriteLine arrFileLines(l)

    Thursday, September 7, 2017 5:16 AM
  • You cannot parse an ".ora" file like that.  It is an arbitrary position sensitive (token level) design.  There is no direct textual comparison method that can work.  You would have to design a parser that an understand the tokens and turn this into a fixed parametrized object definition or similar structure.

    PowerShell and the Net framework have tools that can do this but yu still have to build the basic syntax definitions used to parse the file.  Oracle has not published this syntax map.

    The first step is easy.  Remove all spaces that are not inside of quotes.  Parse all components on either side of a Name/Definition pair.  Compare all elements discovered in each "top level" name/definition.

    You may also be able to just assume that the file has a "name=" at the beginning of a line and use that for your comparison.

    In any case you will have to work this out for yourself and any non-formal method is likely to fail across multiple files as there are no structural format rules for the files.


    Thursday, September 7, 2017 5:26 AM