尾逆/打印一切,除了最后N行? [英] Tail inverse / printing everything except the last n lines?

查看:116
本文介绍了尾逆/打印一切,除了最后N行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个(POSIX命令行)的方式来打印所有文件的除了最后n行?用例是,我将有未知大小的文件,所有这些都包含已知大小,这是我想删除的样板页脚。我在想,如果已经有一个实用工具,写它自己之前做到这一点。

Is there a (POSIX command line) way to print all of a file EXCEPT the last n lines? Use case being, I will have multiple files of unknown size, all of which contain a boilerplate footer of a known size, which I want to remove. I was wondering if there is already a utility that does this before writing it myself.

推荐答案

大多数版本头(1) - GNU来源,特别是,但不是BSD衍生 - 有一个特点,做到这一点。它会显示该文件的顶部,除了结束,如果你使用一个负数行打印的数量。

Most versions of head(1) - GNU derived, in particular, but not BSD derived - have a feature to do this. It will show the top of the file except the end if you use a negative number for the number of lines to print.

像这样:

head -n -10 textfile

这篇关于尾逆/打印一切,除了最后N行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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