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

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

问题描述

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

I have a very long file which I want to print, but skipping the first 1,000,000 lines, for example. I look 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天全站免登陆