linux 如何显示一个文件的某几行(中间几行)
2016-07-02 17:53
561 查看
【一】从第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行。
一般查看文件:
cat test.txt
tail -f test.txt
若有关键词:
cat test.txt|grep 'xxx'
tail -f test.txt|grep 'xxx'
条件多了,可以多加几个grep
cat test.txt|grep 'xxx' |grep 'yyy'
tail -f test.txt|grep 'xxx' |grep 'yyy'
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行。
一般查看文件:
cat test.txt
tail -f test.txt
若有关键词:
cat test.txt|grep 'xxx'
tail -f test.txt|grep 'xxx'
条件多了,可以多加几个grep
cat test.txt|grep 'xxx' |grep 'yyy'
tail -f test.txt|grep 'xxx' |grep 'yyy'
相关文章推荐
- Linux 下五个顶级的开源命令行 Shell
- linux 安装zeromq的一关键点
- Linux-7基础篇 关于进程的一些事
- linux 安装 python2.7 +配置mysql
- Linux 下串口编程入门
- CentOS7+Zabbix3.0.3安装
- centos7安装jetty9.3.10笔记
- linux 安装命令
- linux常用命令总结
- linux 别名
- Linux环境PostgreSQL源码编译安装
- centos下安装配置vsftpd服务
- CentOS7修改网卡名称为eth0及一些基本设置
- linux配置静态路由的几个方法
- 使用xrdp实现windows 远程桌面 ubuntu linux
- 【札记】CentOS7-linux-在虚拟机上配置IP地址
- Linux多线程──主线程和子线程分别循环一定次数
- Centos下 yum方式安装LAMP
- linux管道通信原理
- 每天一个linux命令30)--chgrp命令