我有一个文件夹,里面有两个不同类型的 .log 文件。在每个日志文件的末尾附近,有一行包含以下信息:
I: -11.4
,“I:”之前有 2 个空格,之后有 10 个空格。我要生成的是单个 .txt 文件,仅从日志文件中命名,其值低于 -11.9,例如:
价值日志.txt
namefile.log -12.0
namefile.log -12.5
namefile.log -13.0
namefile.log -14.0
我正在尝试使用在链接中找到的命令:
docs.microsoft\select-string
superuser.com/questions/1589183/powershell-command-to-find-string-in-a-text-file
命令:
Get-ChildItem "C:\Users\username\Desktop\Logs\*.log" | Where-Object { $_.Attributes -ne "Directory" } | ForEach-Object {
If (Get-Content $_.FullName | Select-String -Pattern "I:") {
New-Object -TypeName PSCustomObject -Property @{
Value = $A} | Out-File "C:\Users\username\Desktop\valuelogs.log" -Append
}
}
但它不会生成包含我需要的信息的输出文件。
编辑:
以下是文件的内容:
注意:预期值是“综合响度:”行下方的最后一个值,这将是每行中存在的所有 I: 值的平均值。
文件内容:
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 198.4 TARGET:-23 LUFS M: -49.8 S: -26.7 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 198.5 TARGET:-23 LUFS M: -50.9 S: -27.1 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 198.6 TARGET:-23 LUFS M: -51.6 S: -27.3 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 198.7 TARGET:-23 LUFS M: -53.0 S: -27.4 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 198.8 TARGET:-23 LUFS M: -53.6 S: -27.5 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 198.9 TARGET:-23 LUFS M: -58.6 S: -28.3 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 199 TARGET:-23 LUFS M: -61.8 S: -28.9 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 199.1 TARGET:-23 LUFS M: -65.0 S: -31.2 I: -11.4 LUFS LRA: 2.4 LU
[Parsed_ebur128_0 @ 000001e14c3b09c0] t: 199.2 TARGET:-23 LUFS M: -68.1 S: -31.9 I: -11.4 LUFS LRA: 2.4 LU
Integrated loudness:
I: -11.4 LUFS
Threshold: -21.5 LUFS
第二个日志文件内容:
请注意,在此日志中,我想要的值在前面Input Integrated:
size=N/A time=00:02:36.90 bitrate=N/A speed=26.1x
size=N/A time=00:02:50.00 bitrate=N/A speed=26.1x
size=N/A time=00:03:03.20 bitrate=N/A speed=26.1x
size=N/A time=00:03:16.50 bitrate=N/A speed=26.1x
size=N/A time=00:03:29.90 bitrate=N/A speed=26.2x
size=N/A time=00:03:33.26 bitrate=N/A speed=26.3x
[Parsed_loudnorm_0 @ 00000193badb3000]
Input Integrated: -7.2 LUFS
Input True Peak: +1.5 dBTP
Input LRA: 3.5 LU
Input Threshold: -17.4 LUFS
尝试这个