Powershell选择介于之间的值



我有一个脚本,它提供昨天的日出和日落时间($sunrise和$sunset,格式为yyyy-MM-dd HH:MM:ss(。我有一个文件(可以是txt或csv(,其中第一列的时间戳格式为yyyy-MM-dd HH:MM:ss,第二列的数字格式为XX.X。使用Powershell Get-Content,我试图返回日出和日落时间之间的所有值,包括日出和日落。使用Select,我可以获得奇异值,但我不知道如何获得倍数,更不用说范围了。

Get-Content C:uv.txt | select (between $sunrise & $sunset)

输入(uv.txt(:

2020-08-11 06:00:00 0.0
2020-08-11 07:00:00 0.0
2020-08-11 08:00:00 0.6
2020-08-11 09:00:00 1.4
2020-08-11 10:00:00 4.2
2020-08-11 11:00:00 6.2
2020-08-11 12:00:00 8.4
2020-08-11 13:00:00 9.3
2020-08-11 14:00:00 9.2
2020-08-11 15:00:00 7.6
2020-08-11 16:00:00 5.6
2020-08-11 17:00:00 3.3
2020-08-11 18:00:00 1.6
2020-08-11 19:00:00 0.5
2020-08-11 20:00:00 0.0
2020-08-11 21:00:00 0.0
2020-08-11 22:00:00 0.0

无法工作的简化脚本(控制台中没有输出,或者如果我发送到外部文件(:

$sunrise  = "2020-08-12 06:32:17"
$sunset   = "2020-08-12 20:06:33"
Get-Content C:daily_values_uv.txt | Where-Object { $_ -ge $sunrise -and $_ -le $sunset }

由于big-endian日期格式,您可以执行:

Get-Content C:uv.txt | Where-Object { $_ -gt $sunrise -and $_ -lt $sunset }

最新更新