![](/img/trans.png)
[英]How to programmatically add a PSCmdlet to a Powershell pipeline?
[英]How to add to a pipeline in PowerShell?
假設我有兩個文件, f1.txt
和f2.txt
。 f1.txt
需要進行一些更正,之后需要同時處理這兩個文件。 如何使用f2.txt
數據將f1.txt
更正的輸出合並到管道?
這是一個例子:
Get-Content f1.txt |
% {
$_ #SOME OPERATION
} # How do I merge this output into the next pipeline?
Get-Content f2.txt |
% {
#COMBINED OPERATIONS on f1.txt output and f2.txt
} > output.txt
我知道我可以將第一個操作保存到一個臨時文件中並再次讀取它以進行組合操作:
...
} > temp.txt
Get-Content temp.txt, f2.txt |
...
但有沒有辦法在不創建緩沖區文件的情況下完成它?
您可以在單個SciptBlock
包裝多個命令並調用它:
& {
Get-Content f1.txt |
% {
$_ #SOME OPERATION
}
Get-Content f2.txt
} |
% {
#COMBINED OPERATIONS on f1.txt output and f2.txt
} > output.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.