Jump to content

FINDSTR workaround needed


Recommended Posts

I tested the script

Test1.txt

  Operating System	   » Microsoft Windows 7 Ultimate 64-bit
Os Version  » 6.1.7600 Ultimate Edition
Build Type  » Multiprocessor Free
Serial Number  » 00426-292-0106894-85791
Processor Name  » Intel(R) Core(TM)2 Quad CPU Q9300 @ 2.50GHz (x64)
Video Card Name  » NVIDIA GeForce 9800 GT
Sound Device Name  » C-Media PCI Audio Device
Network Adapter  » 802.11n Wireless PCI Express Card LAN Adapter
Network Adapter  » Realtek RTL8168C(P)/8111C(P) Family PCI-E Gigabit Ethernet NIC (NDIS 6.20)

Test2.txt

  Computer Name		  » HOME-BETA-2008
Operating System  » Microsoft Windows 7 Ultimate 64-bit
Os Version  » 6.1.7600 Ultimate Edition
Build Type  » Multiprocessor Free
Serial Number  » 00426-292-0106894-85791
Physical Memory  » 8.00 GB
Processor Name  » Intel(R) Core(TM)2 Quad CPU Q9300 @ 2.50GHz (x64)
Video Card Name  » NVIDIA GeForce 9800 GT
Sound Device Name  » C-Media PCI Audio Device
Network Adapter  » 802.11n Wireless PCI Express Card LAN Adapter
Network Adapter  » Realtek RTL8168C(P)/8111C(P) Family PCI-E Gigabit Ethernet NIC (NDIS 6.20)
Computer Type   » KQ499AA-A2L m9360f

Differences.txt

  Computer Name		  » HOME-BETA-2008
Physical Memory  » 8.00 GB
Computer Type   » KQ499AA-A2L m9360f

So the scripts looks for what missing in Test1, From Test2, reports it in Differences.txt

 Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim StrTxt1, StrTxt2, StrTxt3, Ts
'-> First Text File
Set Ts = Fso.OpenTextFile("Test1.txt", 1)
StrTxt1 = Ts.ReadAll
Ts.Close
'-> Second Text File
Set Ts = Fso.OpenTextFile("Test2.txt", 1)
Do Until Ts.AtEndOfStream
StrTxt2 = Ts.ReadLine
If InStr(StrTxt1, StrTxt2) = 0 Then
StrTxt3 = StrTxt3 & StrTxt2 & vbCrLf
End If
Loop
Ts.Close
'-> Third Text File
Set Ts = Fso.CreateTextFile("Differences.txt")
Ts.WriteLine StrTxt3
Ts.Close

Link to comment
Share on other sites


yes you are right, in my attachment i have provided 2 files that dont work properly with the script, i think this is because of common "fragment" issues, something like that, however the bat works properly since its a line by line comparison although takes a year.

anyway its not a huge deal.

thanks again.

Edited by bauxite
Link to comment
Share on other sites

The script only looks for what missing from one file, what you want is a script that looks for what missing from both files.

I write up a script that will look for what missing from both files.

1.txt

XYZ
ABC
notreallyuncommon
onlyin1.txtsodontreallymatter1
onlyin1.txtsodontreallymatter2
x
y
astring1
astring2
astring3
D
E
p
o
i
GV
END

2.txt

uncommon
XYZ
uncommonstring2
astring1
astring2
astring3
A
B
uncommonstring3
C
D
E
i
o
p
V
Z
notreallyuncommon
uncommonstring1
END

What missing from both files are stored Differences.txt

ABC
onlyin1.txtsodontreallymatter1
onlyin1.txtsodontreallymatter2
x
y
GV
uncommon
uncommonstring2
A
B
uncommonstring3
C
V
Z
uncommonstring1

Save As Sort2.vbs

 Dim Dic :Set Dic = CreateObject("Scripting.Dictionary")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Obj, Ts, Txt1
Set Ts = Fso.OpenTextFile("1.txt", 1)
Do Until Ts.AtEndOfStream
Txt1 = Ts.ReadLine
Dic.Add Txt1 ,Txt1
Loop
Ts.Close
Set Ts = Fso.OpenTextFile("2.txt", 1)
Do Until Ts.AtEndOfStream
Txt1 = Ts.ReadLine
If Not Dic.Exists(Txt1) Then
Dic.Add Txt1 ,Txt1
Else
Dic.Remove Txt1
End If
Loop
Ts.Close
Set Ts = Fso.CreateTextFile("Differences.txt")
For Each Obj In Dic.Keys
Ts.WriteLine Obj
Next
Ts.Close

Link to comment
Share on other sites

Your welcome, now the only problem might be in the first loop change

   Do Until Ts.AtEndOfStream
Txt1 = Ts.ReadLine
Dic.Add Txt1 ,Txt1
Loop

Dictionary Objects can not have duplicate objects, so incase 1.txt has say

astring3
astring3

the script would error out because the object exists, this code change prevents that error

   Do Until Ts.AtEndOfStream
Txt1 = Ts.ReadLine
If Not Dic.Exists(Txt1) Then
Dic.Add Txt1 ,Txt1
End If
Loop

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...