我很好奇如何使用以下开头的管道连续两次对文件进行cat:
cat file |
管道后面应该做什么,以便"file"的内容可以连续打印两次?
谢谢
最佳答案
给猫剥皮
的方法有很多种...
你可以这样做:
cat file file
如果文件
包含文本hello world
输出将是:
hello world
hello world
另一种方法可以达到相同的结果:
cat file <(cat file)
如果它必须以 cat file |
开头,那么这也可以:
cat file | cat file file
或者你甚至可以这样做:
cat file | cat - file
然而,更有趣的方法是使用 tee
这是一个管件。来自 BSD 通用命令手册:
The tee utility copies standard input to standard output, making a copy in zero or more files. The output is unbuffered.
所以你可以这样做:
cat file | tee /dev/tty
关于linux - 如何在一个管道中对一个文件进行两次cat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36024588/