红联Linux门户
Linux帮助

linux如何显示一个文件的某几行(中间几行)

发布时间:2016-05-07 11:04:22来源:linux网站作者:JeanCheng

cat + tail + head:

从第3000行开始,显示1000行。即显示3000~3999行

cat filename | tail -n +3000 | head -n 1000

显示1000行到3000行

cat filename| head -n 3000 | tail -n +1000

*注意两种方法的顺序

分解:

tail -n 1000:显示最后1000行

tail -n +1000:从1000行开始显示,显示1000行以后的

head -n 1000:显示前面1000行


用sed命令:

sed -n ‘5,10p’ filename
这样你就可以只查看文件的第5行到第10行。


用awk处理:

awk ‘NR==2, NR==11{print}’ input_file

或者

awk ‘NR>2 && NR<11 {print $0}’ input_file


本文永久更新地址:http://www.linuxdiyf.com/linux/20413.html