Display certain line(s) from a text file in Linux.

Posted zhchoutai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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:

  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.的主要内容,如果未能解决你的问题,请参考以下文章

i am a hundred percent certain

display:line-block

ImportError:cannot import name ‘display‘ File “XX“, line 5, in <module> from IPython import display

工资系统

递归删除所有以

php对nesc编译后的文件处理