admin管理员组

文章数量:1559070

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/questions/133692/how-to-display-certain-lines-from-a-text-file-in-linux

本文标签: