【发布时间】:2021-07-12 23:45:44
【问题描述】:
我在 test.dat 下面有这个文件
<category>Games</category>
</game>
<category>Applications</category>
</game>
<category>Demos</category>
</game>
<category>Games</category>
<description>MLB 2002 (USA)</description>
</game>
<category>Bonus Discs</category>
</game>
<category>Multimedia</category>
</game>
<category>Add-Ons</category>
</game>
<category>Educational</category>
</game>
<category>Coverdiscs</category>
</game>
<category>Video</category>
</game>
<category>Audio</category>
</game>
<category>Games</category>
</game>
如何使用Get-Content 和Select-String 从上述文件的输入将以下内容输出到终端。使用上面的输入,我需要接收这个输出。
<category>Games</category>
</game>
<category>Games</category>
</game>
这是我当前正在使用的命令,但它不起作用。
Get-Content '.\test.dat' | Select-String -pattern '(^\s+<category>Games<\/category>\n^\s+<\/game>$)'
【问题讨论】:
-
看起来像 xml 那么为什么不作为 xml 处理呢?你打算用不匹配过滤掉什么?您实际上想要达到什么目的?请提供预期结果。
-
它是 xml 但这是我熟悉的唯一方式。基本上我只需要去掉
Games -
去掉它并留下文件的其余部分?将其剥离并完全按照您在那里展示的方式存储?你想究竟得到什么?请编辑您的帖子以提供这些重要的详细信息。
-
我已经为你简化了。
标签: regex powershell text select-string