在 powershell 中搜索包含双引号的字符串 windows 8
Search for string which has double quotes in 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"
我有一个包含以下内容的文件 -
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"