我有一个通过 HTTP 访问日志的脚本,根据正则表达式过滤掉一些行并将它们复制到另一个文件中:
param($workingdate=(get-date).ToString("yyMMdd"))
Get-Content "access-$workingdate.log" |
Select-string -pattern $pattern |
Add-Content "D:\webStatistics\log\filtered-$workingdate.log"
我的日志可能非常大(最多 2GB),运行最多需要 15 分钟。有什么我可以做的来提高上述陈述的表现吗?
谢谢你的想法!
最佳答案
看看这是否比您当前的解决方案更快:
param($workingdate=(get-date).ToString("yyMMdd"))
Get-Content "access-$workingdate.log" -ReadCount 2000 |
foreach { $_ -match $pattern |
Add-Content "D:\webStatistics\log\filtered-$workingdate.log"
}
关于regex - 提高 PowerShell 过滤语句的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32000445/