windows - 在powershell windows 8中搜索具有双引号的字符串
问题描述
我有一个包含以下内容的文件 -
serial_no= 1 name="abc.txt" type="Text" date="25-06-18"
serial_no= 2 name="abc.bmp" type="Bitmap" date="23-06-18"
serial_no= 3 name="abc.jpg" type="Image" date="21-06-18"
serial_no= 4 name="abc2.txt" type="Text" date="26-06-18"
serial_no= 5 name="abc.log" type="LogFile" date="19-06-18"
serial_no= 6 name="abc.exe" type="Program" date="20-06-18"
serial_no= 7 name="abc.jar" type="Java Archive" date="25-06-18"
serial_no= 8 name="abc3.txt" type="Text" date="11-06-18"
我想搜索type="Text"
我尝试了 Select-String 与 -pattern 选项的许多值,但总是得到错误 -
命令 -
Select-String -path "path\filename.log" -pattern "type="Text""
错误 -
Select-String : A positional parameter cannot be found that accepts argument 'Text'.
At line:1 char:1
+ Select-String -path "...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-String], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectStringCommand
有人能告诉我如何修改我的命令来搜索这样一个带有双引号的字符串吗?
解决方案
'
您可以通过使用而不是"
在外部找到字符串:
Select-String -path "path\filename.log" -pattern 'type="Text"'
为您提供正确的输出(例如):
filename.log:1:serial_no= 1 name="abc.txt" type="Text" date="25-06-18"
filename.log:4:serial_no= 4 name="abc2.txt" type="Text" date="26-06-18"
filename.log:8:serial_no= 8 name="abc3.txt" type="Text" date="11-06-18"
推荐阅读
- kubernetes - 如何从代码在 Grafana 中配置 Cloudflare 应用程序?
- asp.net - 一个来自rest服务的数据表和另一个来自SQL数据库的数据表,需要将SQL数据集附加到现有的数据表中
- python - 使用带有递归神经网络的顺序模型
- ios - Ionic 3 PWA 在 iOS 上无法顺利更新
- node.js - 如何使用环回 4 隐藏一条路由的开放 API 规范
- arrays - 如何在 laravel 集合中将数据访问方式从 data[key] 更改为 data->key?
- bash - 在文本文件中,根据另一个文件将模式替换为其他模式
- c# - 如何以编程方式获取 VC++ 包含目录?
- java - 如何将选定的列写入 Kafka 主题?
- coq - 如何找到对列表的长度