gpt4 book ai didi

powershell - Powershell txt文件过滤

转载 作者:行者123 更新时间:2023-12-03 00:26:13 26 4
gpt4 key购买 nike

我有一个这样的日志文件,其中包含很多行。

connected to TEST01:5555
connected to Android-TEST:5555
up time: 01:39:18, idle time: 06:20:37, sleep time: 00:00:00

connected to TEST02:5555
up time: 01:39:27, idle time: 05:53:12, sleep time: 00:00:00

connected to TEST03:5555
up time: 01:38:27, idle time: 06:24:59, sleep time: 00:00:00

connected to TEST04:5555
up time: 01:39:21, idle time: 06:25:28, sleep time: 00:00:00

connected to TEST05:5555
up time: 18 days, 22:03:19, idle time: 74 days, 04:25:45, sleep time: 00:00:00

connected to TEST06:5555
connected to TEST07:5555
connected to TEST08:5555
up time: 01:49:30, idle time: 07:11:23, sleep time: 00:00:00

connected to TEST09:5555
up time: 18:53:29, idle time: 3 days, 01:51:07, sleep time: 00:00:00

我想通过Powershell仅包含2列(设备名称和运行时间)来输出报告。

我找不到一种制作模式来选择字符串或在哪里对象的方法。

有什么想法吗?

最佳答案

这对您的数据有用吗?

$filename = '<filename>'

$regex =
@'
(?ms)connected to (\S+)\s*
up time: ([0-9:]+).+
'@

Get-Content $filename -Delimiter 'sleep time' |
foreach {
if ($_ -match $regex)
{
[PSCustomObject]@{
DeviceName=$Matches[1]
UpTime = $Matches[2]
}
}
}

关于powershell - Powershell txt文件过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28951202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com