过去,我一直在Windows PowerShell ISE中使用以下内容搜索包含大量文本文件的文件夹,查找包含指定文本的行并将这些行返回到新的文本文件中。
Param (
[Parameter(Mandatory=$true)]
[string] $FullyQualifiedPath
)
$OutputFile = "Output File Pathway"
$FullyQualifiedPath = "Search Files Pathway"
$Pat1 = [regex] 'Search For This Text'
Remove-Item "$OutputFile"
Get-ChildItem -Path "$FullyQualifiedPath" |
Get-Content | Select-String -Pattern $Pat1 -AllMatches >> "$OutputFile"
到目前为止,它运行良好。但是,我现在为获得相同的效果但具有多种模式而感到困惑。
我尝试了以下操作:
Param (
[Parameter(Mandatory=$true)]
[string] $FullyQualifiedPath
)
$OutputFile = "Output File Pathway"
$FullyQualifiedPath = "Search Files Pathway"
$Pat1 = [regex] 'Search For This Text'
$Pat2 = [regex] 'Search For This Text As Well"
Remove-Item "$OutputFile"
Get-ChildItem -Path "$FullyQualifiedPath" |
Get-Content | Select-String -Pattern $Pat1 -AllMatches >> "$OutputFile"
Get-Content | Select-String -Pattern $Pat2 -AllMatches >> "$OutputFile"
但这返回:
Search For This Text Search For This Text Search For This Text Search For This Text As Well Search For This Text As Well Search For This Text As Well
与我的要求相反:
Search For This Text Search For This Text As Well Search For This Text Search For This Text As Well Search For This Text Search For This Text As Well
反正我可以根据需要将其输出吗?
我对这种语言完全不熟悉,原始代码来自在线资源。任何帮助,将不胜感激!