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

Purpose:

Display certain line or lines from a text file, such as :

Display the 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.logsed -n ‘1000,1020p; 1021q’ message.log #break after read out 1020th line.Using awk:awk ‘{if ((NR >= 1000) && (NR <= 1020)) print $0}’ message.logUsing 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 20head -n 1000 message.log | tail +20Ref:

版权声明:本文为博主原创文章,未经博主允许不得转载。

,昨晚多几分钟的准备,今天少几小时的麻烦。

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

相关文章:

你感兴趣的文章:

标签云: