1

我有两个文件

文件 1:

PROCESS_NAME

wf_1

wf_2

wf_3

文件 2:

wf_1 - [运行]

wf_2 - [成功]

wf_2 - [成功]

所以现在我需要比较上述两个文件,并且必须删除 file1 中 file2 中状态为 [Succeeded] 的名称。挣扎了3天。

结果应该是

文件 1:

wf_1

感谢任何帮助。

4

2 回答 2

1

干得好

@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (file1.txt) do (
for /f "skip=1 tokens=*" %%b in ('find "[Succeeded]" file2.txt') do (
set check=%%b
set check=!check: - [Succeeded]=!
if "%%a"=="!check!" set bool=true
)
if not "!bool!"=="true" echo %%a >>new.txt
)
del file1.txt /f /q
ren new.txt file1.txt

只需将file1.txtand替换file2.txt为您的实际文件名。

于 2013-01-22T13:36:25.600 回答
0
Const ForReading = 1
Const TextCompare = 1

Dim File1, File2, OutputFile

File1 = "D:\1t\test1\ddir11.txt"
File2 = "D:\1t\test1\ddir12.txt"
OutputFile = "D:\1t\test1\outfile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
If ObjFSO.FileExists(File1) Then
  Dim objFile1 : Set objFile1 = objFSO.OpenTextFile(File1, ForReading)
Else
  WScript.Quit
End If

' Dictionary object for reference file.
Dim RefDict : Set RefDict = CreateObject("Scripting.Dictionary")
RefDict.CompareMode = TextCompare

Dim StrLine, SearchLine, strNotFound

' Read reference file into dictionary object.
Do Until objFile1.AtEndOfStream
  StrLine = Trim(objFile1.ReadLine)
  'MsgBox (StrLine)
  if Not RefDict.Exists(StrLine) Then
    RefDict.Add StrLine, "1"
  End If
Loop

Dim a,s,i
a = RefDict.Keys
'read dictionary....
'For i = 0 To RefDict.Count -1 ' Iterate the array.
'   s = s & a(i) & "<BR>" ' Create return string.
'Next
objFile1.Close

' File that may have more or less lines.
If ObjFSO.FileExists(File2) Then
  Dim objFile2 : Set objFile2 = objFSO.OpenTextFile(File2, ForReading)
Else
  WScript.Quit
End If

' Search 2nd file with reference file.
Do Until objFile2.AtEndOfStream
  SearchLine = Trim(objFile2.ReadLine)
  If Not RefDict.Exists(SearchLine) Then
    If IsEmpty(strNotFound) Then
      strNotFound = SearchLine
    Else
      strNotFound = strNotFound & vbCrlf & SearchLine
    End If
  End If
Loop

objFile2.Close

If IsEmpty(strNotFound) or strNotFound = "" Then

End If

Dim objFile3 : Set objFile3 = objFSO.CreateTextFile(OutputFile, True)
MsgBox ("str:" & strNotFound)
objFile3.WriteLine strNotFound
objFile3.Close
于 2017-06-03T14:09:42.403 回答