小编典典

在Bash中跳过前X行打印文件

linux

我有一个很长的文件要打印,但是例如跳过前1,000,000行。我查看了cat手册页,但是没有看到任何选择。我正在寻找执行此操作的命令或简单的Bash程序。


阅读 296

收藏
2020-06-02

共1个答案

小编典典

你需要尾巴。一些例子:

$ tail great-big-file.log
< Last 10 lines of great-big-file.log >

如果您确实需要跳过特定数量的“第一行”,请使用

$ tail -n +<N+1> <filename>
< filename, excluding first N lines. >

即,如果要跳过N行,则开始打印N + 1行。例:

$ tail -n +11 /tmp/myfile
< /tmp/myfile, starting at line 11, or skipping the first 10 lines. >

如果只想看最后几行,请省略“ +”号:

$ tail -n <N> <filename>
< last N lines of file. >
2020-06-02