"Leetcode~shell": Tenth Line

Source: Internet
Author: User

Tenth line:https://leetcode.com/problems/tenth-line/


Test Instructions: prints the 10th line of a file.

The problem involves several points:

1. How do I read a file?

2. How do I find line 10th?

3. What if the file is empty or less than 10 lines?

Solution:

1.shell a way to read a file:

While read Linedo     echo $linedone < filename
2. Use the Count method to find the 10th line.

3. If the file is empty or less than 10 lines, the output is empty.


Code:

Cnt=1while Read Linedo    if [$ (cnt)] = = [ten]; then        echo $line    fi let    cnt+=1done < file.txt if [$cnt- LT Ten];then    echo "fi



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Leetcode~shell": Tenth Line

Related Article

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.