保留一些管道的值以最终输出 [英] Retain values from some pipes for final output

查看:68
本文介绍了保留一些管道的值以最终输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何做

PS> A | B | C | Format-Table PropertyFromA, PropertyFromB, PropertyFromC

例如

gci -r -i *.txt | Get-Content | where {$_.Contains("SomeText")} | FormatTable -Property {$_.Directory, $.Name}

在这种情况下,gci输出将具有目录",名称"的属性,但是当我通过Get-Content传递时,这些属性将丢失.我该如何存储它并在以后通过管道传递到Format-Table时使用.一个管道链命令就能很好地实现所有这些功能吗?

In this case gci output will have properties of Directory, Name but these will be lost when I pipe through Get-Content. How do I store this and make use later when piped to Format-Table. Can all this be achieved nicely in a single pipe chain command?

推荐答案

对命令进行少量修改即可:

A small modification to your command will work:

gci -r -i *.txt | ? { (gc $_.FullName) -Match "SomeText" } | FormatTable Directory,Name

这篇关于保留一些管道的值以最终输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆