在文件中打印最后n-2行的优雅方式

时间:2013-02-08 12:20:31

标签: bash

我想打印文件的最后n-2行,其中n是文件中的行数。 这可以通过执行n = wc -l -2然后tail -n $file来完成。

但有没有更好的方法呢?我经常在bash中使用这个函数......

2 个答案:

答案 0 :(得分:8)

您可以使用tail -n +3 file跳过前两行(并输出其余的n-2行)。

答案 1 :(得分:5)

如果我理解正确,tail -n +3 file应该做你想做的事。

来自man tail

       -n, --lines=K
          output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth
相关问题