csv - 在文件中查找字符串并复制该行
问题描述
我正在处理一个 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
推荐阅读
- linux - 在 shell 脚本中取消 sudo 提示
- javascript - Nuxt.js 页面转换,@leave 永远不会执行
- php - 使用PHP获取每两个特定字符之间的字符串
- machine-learning - pytorch 会在网络中使用 python 计算代码正确执行吗?
- c++ - C ++无法引用地图的键
- security - 百度地图api是如何工作的?
- javascript - 在加载时加载随机背景视频而不重复相同的视频
- postgresql - Aurora RDS Postgres - 使用 PgAdmin3 通过 SSL 连接
- jquery - iPhone - 非英文数字的输入字段问题
- python - Google Speech API RecognitionConfig 没有“speechContexts”字段错误