一个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”,则替换第二个字段的值,然后将数据写回文件。 –