在文件中查找字符串并复制行

时间:2018-10-11 01:28:21

标签: csv vbscript

我正在处理CSV文件,我想检查其中是否有特定的字符串。如果是这样,我想复制找到该字符串的行。

代码:

x = InputBox("String to find")

fileName = "file.csv"

Set oshell = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")

Set fich = fs.OpenTextFile(fileName, 1, "True")

linea = fich.ReadAll

'here I want to read the row where I found the value of x

line = Left (linea, 117)
MsgBox line

fich.Close

1 个答案:

答案 0 :(得分:2)

您逐行阅读。

Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Do Until Inp.AtEndOfStream
    Text = Inp.readline
    If InStr(LCase(Text), "cat") then Msgbox Text
Loop

要在命令提示符下使用

cscript //nologo C:\folder\file.vbs < C:\folder\FileToSearch.txt