我有一个包含重复文本模式的文本文件(STIG审核文档)
Sample: Group ID (Vulid): V-71989 Group Title: SRG-OS-000445-GPOS-00199 . Vulnerability Discussion: ... Check Content:... <hash symbol> some command .
我想输出以“Group ID(Vulid)”开头的行 并且以文件中存在的顺序以“#”开头的行。
我试过了:
Get-Content C:\in-file.txt | (Where-Object {$_ -match 'Group ID'}) | (Where-Object {$_ -match '#'}) | Set-Content C:\out.txt
但它在“Or”上是barfs。
答案 0 :(得分:0)
Bill_Stewart is trying to say应该是什么:
Get-Content C:\in-file.txt |
Where-Object {$_ -match 'Group ID' -or $_ -match '#'} |
Set-Content C:\out.txt
多线是为了便于阅读;你可以在代码中将它作为一行。