linux - 如何在一个管道中对一个文件进行两次cat

标签 linux bash shell scripting

我很好奇如何使用以下开头的管道连续两次对文件进行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/

相关文章:

php - 使 apache 别名指向 trucrypt 容器中的文件夹

linux - 在同一行打印输出

BASH - 定时输入 - 显示倒计时

linux - 如何在不传递日期参数的情况下查看目录中最后创建的 3 个文件

c - 管道只执行一次命令

linux - 这行shell脚本代码是什么意思

PHP与html混合无输出

bash - UNIX 中的模式匹配解释

linux - 使用 Zoidberg 或 Term::Shell ( Perl 模块 ) 哪一个更好地在 Perl 中实现自定义 shell?

c - 在循环和多个操作中使用选择系统调用