我将其保存在日志文件中,并且我只希望新日志文件或变量中不包含(s)的时间,谢谢您的答复。
Fri Nov 02 13:47:07 2018 time =5.803s
Fri Nov 02 14:02:10 2018 time =7.082s
我的代码
Get-Content "logfile.txt" |
select-string -pattern "5" |
foreach-object{
write-Output $_ >> "C:\Users\titi\Desktop\test.txt"
}
答案 0 :(得分:1)
这将获得您似乎想要的信息... [咧嘴]
# fake reading in a text file
# in real life, use Get-Content
$InStuff = @'
Fri Nov 02 13:47:07 2018 time =5.000s
Fri Nov 02 13:47:07 2018 time =5.803s
Fri Nov 02 14:02:10 2018 time =7.082s
Fri Nov 02 13:47:07 2018 time =4.000s
Fri Nov 02 13:47:07 2018 time =3.000s
Fri Nov 02 13:47:07 2018 time =5.001s
'@ -split [environment]::NewLine
$MinimumSeconds = 5.0
$Results = foreach ($IS_Item in $InStuff)
{
$Seconds = [decimal]($IS_Item.Split('=')[1].Trim().TrimEnd('s'))
if ($Seconds -gt $MinimumSeconds)
{
$Seconds
}
}
''
$Results
输出...
5.803
7.082
5.001
上面发生了什么...
[decimal]
值$Results
集合将其保存回文件将使用Set-Content。 [咧嘴]