haz*_*ard 4 powershell pipeline
假设我有两个文件,f1.txt并且f2.txt.f1.txt需要进行一些修正,之后需要同时处理这两个文件.如何将f1.txt修正输出与f2.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
Run Code Online (Sandbox Code Playgroud)
我知道我可以将第一个操作保存到一个临时文件中并再次读取它以进行组合操作:
...
} > temp.txt
Get-Content temp.txt, f2.txt |
...
Run Code Online (Sandbox Code Playgroud)
但有没有办法在不创建缓冲区文件的情况下完成它?
您可以将多个命令包装SciptBlock在一起并调用它:
& {
Get-Content f1.txt |
% {
$_ #SOME OPERATION
}
Get-Content f2.txt
} |
% {
#COMBINED OPERATIONS on f1.txt output and f2.txt
} > output.txt
Run Code Online (Sandbox Code Playgroud)