unix - 文件的头部和尾部 [英] unix - head AND tail of file

查看:11
本文介绍了unix - 文件的头部和尾部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有一个txt文件,同时查看文件的前10行和后10行的命令是什么?

Say you have a txt file, what is the command to view the top 10 lines and bottom 10 lines of file simultaneously?

即如果文件长 200 行,则一次性查看 1-10 和 190-200 行.

i.e. if the file is 200 lines long, then view lines 1-10 and 190-200 in one go.

推荐答案

您可以简单地:

(head; tail) < file.txt

如果你出于某种原因需要使用管道,那么像这样:

And if you need to uses pipes for some reason then like this:

cat file.txt | (head; tail)

注意:如果file.txt中的行数小于默认头部行数+默认尾部行数,将打印重复行.

Note: will print duplicated lines if number of lines in file.txt is smaller than default lines of head + default lines of tail.

这篇关于unix - 文件的头部和尾部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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