While read line cannot read the last row

Source: Internet
Author: User

Transfer from http://openwares.net/linux/while_read_line_last_line.html

Just used, thank you very much, stay here for backup;

While reading line reads a file, if the last line of the file does not have a newline character \ n, then read reads the last line with the file Terminator eof, and the loop terminates, although there is a last line in $line, but the program has no chance to process this line again. Therefore, the following code can be used to resolve this problem:

123 whilereadline || [[ -n ${line} ]]; do...done

This will not test the-n $line when the file is not finished, and will still be able to continue processing by testing whether the $line has content when it encounters the end of the file.

While read line cannot read the last row

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.