学习 grep 命令并遇到了这个它如何与tail结合使用?

问题描述

会怎样 grep '&' input.txt | tail -4 给我?我对此很陌生,无法弄清楚将 grep 和 tail 一起使用会发生什么。

解决方法

tail -4 与文件一起执行时通常会打印文件的最后四行

与:

grep '&' input.txt | tail -4

正在对 grep 命令的输出执行 tail 命令,因此将打印 grep 输出的最后 4 行。

例如,如果 input.txt 中出现 50 次“&”,则只会打印最后 4 次。