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:
- http://serverfault/questions/133692/how-to-display-certain-lines-from-a-text-file-in-linux
本文标签:
j9九游会老哥俱乐部交流区的版权声明:本文标题:display certain line(s) from a text file in linux. 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1727340996a1109407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论