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:

  1. http://serverfault.com/questions/133692/how-to-display-certain-lines-from-a-text-file-in-linux

Display certain line(s) from a text file in Linux.的更多相关文章

  1. create feature from text file

    '''---------------------------------------------------------------------------------- Tool Name: Cre ...

  2. New text file line delimiter

    Window -> Preferences -> General -> Workspace : Text file encoding :Default : 选择此项将设定文件为系统默 ...

  3. [转]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 ...

  4. unity, read text file

    using System.IO; //test read txt        //Resources.Load(...) loads an asset stored at path in a Res ...

  5. [转]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 ...

  6. eclipse设置text file encoding UTF-8和文件的换行符 Unix 格式

    阿里华山版java开发手册代码格式第10条: 步骤:1.Window - Preferences, 2.左边选择 General - Workspace , 3.右边Text file encodin ...

  7. shell脚本执行时报"bad interpreter: Text file busy"的解决方法

    在执行一个shell脚本时,遇到了“-bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy”错误提示,如下所示: [or ...

  8. eclipse的使用-------Text File Encoding没有GBK选项的设置

    eclipse的使用-------Text File Encoding没有GBK选项的设置 2013-12-25 09:48:06 标签:java myeclipse使用 有一个项目是使用GBK编码的 ...

  9. 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 ...

随机推荐

  1. 一个Velocity Template Language学习的框架

    Velocity Template Language(VTL)使得数据展示和后台代码的开发分离开来,最初用在基于servlet的网站开发上,它的这一特性使得它在应付MVC Web开发模式时显得尤其合适 ...

  2. 【转】MySQL常见的运算符及使用

    转自:http://www.linuxidc.com/Linux/2016-03/129672.htm MySQL中有4类运算符,它们是: 算术运算符 比较运算符 逻辑运算符 位操作运算符 算术操作符 ...

  3. Microsoft SQL Server学习(六)--查询语句

    联合查询 use student --建表 create table class_A( id int primary key, name varchar(50), sex char(50), cour ...

  4. http链接中请求进行编码,Http请求

    如果参数中含有特殊字符&,则强制URL编码<br> http协议中参数的传输是"key=value"这种简直对形式的,如果要传多个参数就需要用“&”符号 ...

  5. thinkphp信息修改和分页

    关联两个数据表,在Model里建立StuModel.class.php: <?php //Belongs_to 关联表示当前模型从属于另外一个父对象 namespace Admin\Model; ...

  6. Masonry 原理一

    Under the hood Auto Layout is a powerful and flexible way of organising and laying out your views. H ...

  7. WindowsForms获取服务名称

    StringBuilder sb = new StringBuilder(); ServiceController[] services = ServiceController.GetServices ...

  8. 怎么让Eclipse对html和js代码自动提示

    使用eclipse自带的插件,无需另外安装插件,具体步骤如下1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist修改Auto Activ ...

  9. 【转】Go语言入门教程(一)Linux下安装Go

    说明 系统是Ubuntu. 关于安装 下载安装包 当前官方下载地址是https://golang.org/dl/,如果不能访问,请自行FQ,FQ是技术工作者的必备技能. 安装 tar -xzvf go ...

  10. xmpp获取好友信息和添加删除好友(4)

    原始地址: XMPPFrameWork IOS 开发(五)获取好友信息和添加删除好友 好友列表和好友名片 [_xmppRoster fetchRoster];//获取好友列表 //获取到一个好友节点 ...