1

我正在尝试使用 PowerShell 从目录中的文件中提取与特定模式匹配的所有文本。然而,由于某种原因,它似乎无限循环(输出是一组无限重复的相同结果,脚本永远不会完成)。拜托,谁能给我一个关于问题是什么的提示?

$input_path = 'C:\Users\*.txt'
$output_file = 'C:\Users\*.txt'
$regex = '[A-Za-z]+?_V[A-Z][A-Z0]?[A-Z]? [A-Za-z]+?_R[A-Z][A-Z]?V?'
select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
4

1 回答 1

1

正如评论中所指出的,您可能应该将输出保存到不同的文件夹或将文件(不仅仅是路径)捕获到变量中。像这样的东西:

$input_files = Get-Childitem 'C:\Users\*.txt'
$output_file = 'C:\Users\output.txt'
$regex = '[A-Za-z]+?_V[A-Z][A-Z0]?[A-Z]? [A-Za-z]+?_R[A-Z][A-Z]?V?'
($input_files | Select-String -Pattern $regex -AllMatches).Matches.Value > $output_file
于 2018-05-15T20:37:42.610 回答