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

Source: Internet
Author: User

Purpose:

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

Display the t h Line from File Message.log

Or

Display the lines between 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.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 20head -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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.