如何从管道中两次使用STDIN [英] How to use STDIN twice from pipe
本文介绍了如何从管道中两次使用STDIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似
awk 'FNR==NR {col1[$1]++; col2[$2]++; next} {print $0, col2[$2] "/" length(col1)}' input input
但是如果我有很多文件,并且需要将此脚本用于串联的文件,例如:
But in case I have lot of files and need to use this script for concatenated files together like:
cat *all_input | awk 'FNR==NR {col1[$1]++; col2[$2]++; next} {print $0, col2[$2] "/" length(col1)}' STDIN STDIN
不起作用.如何从管道中两次使用STDIN?
Does not work. How to use STDIN twice from pipe?
推荐答案
您不需要使用管道.如果您使用的是bash
,请使用将进程替换为<(cmd)
,即实现重定向,使过程的输入或输出(某些命令序列)显示为临时文件.
You don't need to use a pipe. If you are using bash
use process-substitution as <(cmd)
i.e. to achieve a redirection where the input or output of a process (some sequence of commands) appear as a temporary file.
awk 'FNR==NR {col1[$1]++; col2[$2]++; next} {print $0, col2[$2] "/" length(col1)}' <(cut -f3 5- input) <(cut -f3 5- input)
这篇关于如何从管道中两次使用STDIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文