一個simplyfied版本script @abr mentioned的:
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim tsIn : Set tsIn = goFS.OpenTextFile("..\data\46734115.csv")
Dim tsOut : Set tsOut = goFS.CreateTextFile("..\data\46734115-2.csv")
Dim sLine
Do Until tsIn.AtEndOfStream
sLine = tsIn.ReadLine()
WScript.Echo "<", sLine
If "456," = Left(sLine, 4) Then
sLine = "789,""something else"""
End If
WScript.Echo ">", sLine
tsOut.WriteLine sLine
WScript.Echo
Loop
tsOut.Close
tsIn.Close
輸出:
type ..\data\46734115.csv
123,"Active"
456,"Not-Active"
999000123,"Active"
cscript 46734115-3.vbs
< 123,"Active"
> 123,"Active"
< 456,"Not-Active"
> 789,"something else"
< 999000123,"Active"
> 999000123,"Active"
type ..\data\46734115-2.csv
123,"Active"
789,"something else"
999000123,"Active"
[打開,編輯和重新保存一個CSV文件(可能的重複https://stackoverflow.com/questions/19936645/open-edit-and-re- save-a-csv-file) – abr
@abr沒有那是刪除重複的文本,但沒有找到文本,然後編輯該文本右側的文本。不一樣,或者更糟糕,不是肯定的重複 – compcobalt
您讀取文件,以逗號分隔每行,如果第一個字段的值爲「456」,則替換第二個字段的值,然後將數據寫回文件。 –