Display certain line(s) from a text file in Linux.
Purpose:
Display certain line or lines from a text file, such as :
Display the 1000th line from file message.log
or
Display the lines between 1000 and 1020 from file message.log
Solution:
Using sed:
sed -n '1000,1020p' message.log
sed -n '1000,1020p; 1021q' message.log #break after read out 1020th line.
Using awk:
awk '{if ((NR >= 1000) && (NR <= 1020)) print $0}' message.log
Using cat && grep:
cat -n message.log | grep -A 20 '^ *1000'
Using nl && grep:
nl message.log | grep -A 20 '^ *1000'
Using tail && head:
tail -n +1000 message.log | head 20
head -n 1000 message.log | tail +20
Ref:
Display certain line(s) from a text file in Linux.的更多相关文章
- create feature from text file
'''---------------------------------------------------------------------------------- Tool Name: Cre ...
- New text file line delimiter
Window -> Preferences -> General -> Workspace : Text file encoding :Default : 选择此项将设定文件为系统默 ...
- [转]How to Import a Text File into SQL Server 2012
Importing a using the OpenRowSet() Function The OPENROWSET bulk row set provider is accessed by call ...
- unity, read text file
using System.IO; //test read txt //Resources.Load(...) loads an asset stored at path in a Res ...
- [转]Loading, Editing, and Saving a Text File in HTML5 Using Javascript
本文转自:http://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-htm ...
- eclipse设置text file encoding UTF-8和文件的换行符 Unix 格式
阿里华山版java开发手册代码格式第10条: 步骤:1.Window - Preferences, 2.左边选择 General - Workspace , 3.右边Text file encodin ...
- shell脚本执行时报"bad interpreter: Text file busy"的解决方法
在执行一个shell脚本时,遇到了“-bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy”错误提示,如下所示: [or ...
- eclipse的使用-------Text File Encoding没有GBK选项的设置
eclipse的使用-------Text File Encoding没有GBK选项的设置 2013-12-25 09:48:06 标签:java myeclipse使用 有一个项目是使用GBK编码的 ...
- Writing Text File From A Tabular Block In Oracle Forms
The example given below for writing text file or CSV using Text_IO package from a tabular block in O ...
随机推荐
- 373 Find K Pairs with Smallest Sums 查找和最小的K对数字
给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k.定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2.找到和最小的 k 对数字 (u1,v1 ...
- sql Server与ORACLE的语法区别 自用整理!
/*整理背景201403订单中心数据库迁移(整理Oracle与SQL的差异)整理规则第一句为SQL Server 第二句为Oracle*/--数据类型int integervarchar varcha ...
- socket相关函数
socket() 我们使用系统调用socket()来获得文件描述符:#include<sys/types.h>#include<sys/socket.h>int socket( ...
- lsb_release No LSB modules are available
lsb_release 提示: No LSB modules are available 执行: sudo apt-get install lsb-core
- Flask框架 之request对象
一.request对象属性 属性 说明 类型 data 记录请求的数据,并转换为字符串 * form 记录请求中的表单数据 MultiDict args 记录请求中的查询参数 MultiDict co ...
- java Object类中方法介绍
- 观察者模式在Foundation框架通知中的应用
GitHub传送门 1.何为观察者模式? 观察者设计模式定义了对象间的一种一对多的依赖关系,以便一个对象的状态发生变化时,所有依赖于它的对象都得到通知并自动刷新. 举个简单的例子:你和你的舍友都订阅了 ...
- JS的filter用法
filter也是一个常用的操作,它用于把Array的某些元素过滤掉,然后返回剩下的元素. 和map()类似,Array的filter()也接收一个函数.和map()不同的是,filter()把传入的函 ...
- 浅谈es6 promise
本文是借鉴于ac黄的博客. 接触es6也有几个月了,貌似没有系统的去学习过它,总是用到什么,查查什么.今天就说下es6中的promise对象. 先说说promise解决了什么问题? 写前端的同学都经常 ...
- css去掉div的滚动条
懒得讲原理了,直接贴代码: css部分: .slide-box { margin-top: 200px; display: -webkit-box; overflow-x: scroll; overf ...