通过尾巴和头通过管道三通的文件 [英] Piping a file through tail and head via tee
问题描述
从<起始href=\"http://stackoverflow.com/questions/8624669/unix-head-and-tail-of-file/16637719?noredirect=1#comment23935309_16637719\">here我试图读取文件,并发射头和文件的尾部(读取文件仅一次)。
Starting from here I tried to read a file and emit the head and the tail of the file (reading the file only once).
我试过如下: T恤&GT;(头)&GT;(尾)&GT;的/ dev / null的&LT;的text.txt
该行正常工作,但我想摆脱在/ dev / null的的。所以我尝试: T恤&GT;(头)|尾LT;的text.txt
This line works as expected, but I'd like to get rid of the /dev/null. So I tried:
tee >(head) | tail < text.txt
但正如预期的(当然,如我所料),这条线是不行的,它打印头,但之后没有返回。显然,尾巴在等待着什么。但我不知道什么确切。
我发现这个 SO质疑,但我无法得到它与运行给出答案。
But this line does not work as expected (well, as I expected), it prints the head but does not return after that. Apparently tail is waiting for something. But I don't know what for exactly. I found this SO question, but I could not get it running with the given answers.
推荐答案
在 T恤&GT;(头)|尾LT;的text.txt
,文本文件直接到尾
。你可能意味着
In tee >(head) | tail < text.txt
, the text file goes directly to tail
. You probably meant
tee >(head) < text.txt | tail
这不会等待任何事情,但也不管用,因为这两个发球和头部的输出去的尾巴。
Which does not wait for anything, but does not work either, because the output of both tee and head go to tail.
重定向头的输出到一个新的文件描述符,然后把它回来的作品,但我不知道这是干净,然后使用的/ dev / null的:
Redirecting the head's output to a new file descriptor and then taking it back works, but I am not sure it is "cleaner" then using /dev/null:
( tee >(head >&3) < text.txt | tail) 3>&1
这篇关于通过尾巴和头通过管道三通的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!