此命令显示该文件的第二行:UNIX的显示文件的第二行
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
但是我无法理解这个,因为头-2用于打印前两行,而尾-1打印最后一行但打印第二行的方式是怎样的!! ???
tail只在head的输出上运行,'tail -1'表示打印最后一行输出。在这种情况下(在管道中),“tail”不知道myfile存在。您的管线按设计工作,您观察的内容被认为是一项功能! ;-)。祝你好运。 – shellter