在 Bash 中打印文件,跳过前 X 行 [英] Print a file, skipping the first X lines, in Bash

查看:27
本文介绍了在 Bash 中打印文件,跳过前 X 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的文件要打印,例如跳过前 1,000,000 行.

I have a very long file which I want to print, skipping the first 1,000,000 lines, for example.

我查看了 cat 手册页,但没有看到任何选项可以执行此操作.我正在寻找执行此操作的命令或简单的 Bash 程序.

I looked into the cat man page, but I did not see any option to do this. I am looking for a command to do this or a simple Bash program.

推荐答案

你需要尾巴.一些例子:

You'll need tail. Some examples:

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

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

If you really need to SKIP a particular number of "first" lines, use

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

也就是说,如果要跳过 N 行,则开始打印第 N+1 行.示例:

That is, if you want to skip N lines, you start printing line N+1. Example:

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

如果你只想看到最后这么多行,请省略+":

If you want to just see the last so many lines, omit the "+":

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

这篇关于在 Bash 中打印文件,跳过前 X 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆