3 ways the shell reads files by row _linux Shell

Source: Internet
Author: User
There are a lot of ways, and here are three ways to write:
Writing a:
Copy Code code as follows:
#!/bin/bash
While Read line
Todo
Echo $line
Done < filename (files to be read)


Writing two:
Copy Code code as follows:
#!/bin/bash
Cat filename (Files to be read) | While Read line
Todo
Echo $line
Done


Writing three:
Copy Code code as follows:
For line in ' cat filename (file to be read) '
Todo
Echo $line
Done


Description
For row-by-line reading and while-line-by-row reading are different, such as:
Copy Code code as follows:
$ cat File
1111
2222
3333 4444 555

$ cat File | while read line; do echo $line; Done
1111
2222
3333 4444 555

$ for line in $ (<file); do echo $line; Done
1111
2222
3333
4444
555
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.