在Unix中粘贴没有临时文件 [英] paste without temporary files in Unix

查看:72
本文介绍了在Unix中粘贴没有临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Unix命令粘贴,就像cat的列追加形式一样,遇到了一个我不知道如何在Unix中解决的难题.

I'm trying to use the Unix command paste, which is like a column-appending form of cat, and came across a puzzle I've never known how to solve in Unix.

如何将两个不同程序的输出用作另一个程序的输入(不使用临时文件)?

How can you use the outputs of two different programs as the input for another program (without using temporary files)?

理想情况下,我会这样做(不使用临时文件):

Ideally, I'd do this (without using temporary files):

./progA> tmpA; ./progB> tmpB;粘贴tmpA tmpB

./progA > tmpA; ./progB > tmpB; paste tmpA tmpB

对于我来说,这似乎比较常见,但是我不知道如何使用两个不同程序( progA progB )的输出作为输入到另一个而不使用临时文件( tmpA tmpB ).

This seems to come up relatively frequently for me, but I can't figure out how to use the output from two different programs (progA and progB) as input to another without using temporary files (tmpA and tmpB).

对于诸如粘贴之类的命令,只需使用 paste $(./progA)$(./progB)(用bash表示)就不会成功,因为它可以从文件或stdin中读取

For commands like paste, simply using paste $(./progA) $(./progB) (in bash notation) won't do the trick, because it can read from files or stdin.

我对临时文件保持警惕的原因是,我不想让并行运行的作业通过使用同一文件而引起问题;有时很难确保唯一的文件名.

The reason I'm wary of the temporary files is that I don't want to have jobs running in parallel to cause problems by using the same file; ensuring a unique file name is sometimes difficult.

我目前正在使用bash,但好奇地看到适用于任何Unix shell的解决方案.

I'm currently using bash, but would be curious to see solutions for any Unix shell.

最重要的是,我什至以正确的方式解决了这个问题?

And most importantly, am I even approaching the problem in the correct way?


干杯!

推荐答案

您不需要bash下的临时文件,请尝试以下操作:

You do not need temp files under bash, try this:

paste <(./progA) <(./progB)

请参阅Bash中的流程替代" 手册.

See "Process Substitution" in the Bash manual.

这篇关于在Unix中粘贴没有临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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