Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
由于转义序列,Powershell选择字符串失败_Powershell_Powershell 2.0 - Fatal编程技术网

由于转义序列,Powershell选择字符串失败

由于转义序列,Powershell选择字符串失败,powershell,powershell-2.0,Powershell,Powershell 2.0,我有一个文件,其中有以下内容 change sets: promotion level: INITIAL depends on: GEESF_R2.1.0.9.5179@\My_PVOB (MES@\My_PVOB) My_2.1.0.13.4875@\My_PVOB (Notification@\My_PVOB) MyComponents_8_8_2011.6859@\My_PVOB (SQLReporting@\My_PVOB) My_2.1.0.1

我有一个文件,其中有以下内容

change sets:
  promotion level: INITIAL
  depends on: 
    GEESF_R2.1.0.9.5179@\My_PVOB (MES@\My_PVOB)
    My_2.1.0.13.4875@\My_PVOB (Notification@\My_PVOB)
    MyComponents_8_8_2011.6859@\My_PVOB (SQLReporting@\My_PVOB)
    My_2.1.0.13.7098@\My_PVOB (Support@\My_PVOB)
我想阅读带有图案@\My_PVOB)的内容

所以我像这样写selectstring选项

Select-string -pattern "@\My_PVOB)" -path "C:\Baselines.txt"
但我有以下问题

parsing "@\My_PVOB)" - Unrecognized escape sequence \M.
即使改变模式为

Select-string -pattern "@\\My_PVOB)" -path "c:\Baselines.txt"
我得到以下错误

 "@\\My_PVOB)" - Too many )'s.

你知道怎么解决吗?

圆括号是一个特殊字符,所以你应该转义它:

Select-string -pattern "@\\My_PVOB\)" -path "c:\Baselines.txt"

圆括号是一个特殊字符,因此应将其转义:

Select-string -pattern "@\\My_PVOB\)" -path "c:\Baselines.txt"

可以使用转义方法将元字符替换为其转义码:

PS> $pattern = [regex]::Escape('@\My_PVOB)')
PS> $pattern
@\\My_PVOB\)

PS> Select-String -Path c:\Baselines.txt -Pattern $pattern 

可以使用转义方法将元字符替换为其转义码:

PS> $pattern = [regex]::Escape('@\My_PVOB)')
PS> $pattern
@\\My_PVOB\)

PS> Select-String -Path c:\Baselines.txt -Pattern $pattern 

或者使用
-SimpleMatch
完全避免正则表达式求值。或者使用
-SimpleMatch
完全避免正则表达式求值。