在文件中查找字符串并复制该行
Find a string in a file and copy the row
我正在处理一个 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
你一行一行地读。
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
我正在处理一个 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
你一行一行地读。
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