【发布时间】:2018-08-05 01:59:03
【问题描述】:
如何检查字符串是否存在于:
- 1 个文本文件;
- 最大为 10GB;
- 考虑到文件只有一行;
- 文件只包含随机数1到9;
- 使用powershell(因为我觉得会更高效,虽然我不知道怎么用这种语言编程);
我已经批量尝试过:
FINDSTR "897516" decimal_output.txt
pause
但正如我所说,我需要更快、更有效的方法来做到这一点。
我还尝试了我在 stackoverflow 中找到的这段代码:
$SEL = Select-String -Path C:\Users\fabio\Desktop\CONVERTIDOS\dec_output.txt -Pattern "123456"
if ($SEL -ne $null)
{
echo Contains String
}
else
{
echo Not Contains String
}
但是我得到下面的错误,我不知道这段代码是否最可靠或足够。错误:
Select-String : 提示“System.OutOfMemoryException”异常。 在 C:\Users\fabio\Desktop\1.ps1:1 char:8 + $SEL = 选择字符串-路径 C:\Users\fabio\Desktop\CONVERTIDOS\dec_out ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Select-String], OutOfMemoryException + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.SelectStringCommand
【问题讨论】:
标签: string powershell search