【发布时间】:2012-12-12 12:49:08
【问题描述】:
此命令显示文件的第二行:
cat myfile | head -2 | tail -1
我的文件包含以下数据:
hello
mark
this is the head line
this is the first line
this is the second line
this is the last line
上面的命令将数据打印为:mark
但我无法理解这一点,因为 head -2 用于打印前两行,tail -1 打印最后一行,但如何打印第二行!!???
【问题讨论】:
-
tail 只对 head 的输出进行操作,
tail -1表示打印接收到的最后一行输出。在这种情况下(在管道中),tail不知道 myfile 存在。您的管道正在按设计工作,您观察到的内容被视为一项功能! ;-)。祝你好运。
标签: unix