Shell reads each line of the file

Source: Internet
Author: User

Shell reads each line of the file


Writing one:

----------------------------------------------------------------------------

#!/bin/bash

While Read line

Do

Echo $line

Done < filename (files to be read)

----------------------------------------------------------------------------


Two:

----------------------------------------------------------------------------

#!/bin/bash

Cat filename (file to read) | While Read line

Do

Echo $line

Done

----------------------------------------------------------------------------

If you need to output a line with a specified character, you can write

----------------------------------------------------------------------------

#!/bin/bash

Cat filename (file to read) |  grep Word (Specify character) | While Read line

Do

Echo $line

Done

----------------------------------------------------------------------------


Three:

----------------------------------------------------------------------------

For line in ' cat filename (file to be read) '

Do

Echo $line

Done

----------------------------------------------------------------------------


Description

For row-by-line reading and while progressive reading are different, such as:

The file contents are 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


This article is from the "Big Meow Downhill" blog, please make sure to keep this source http://damiao.blog.51cto.com/8194496/1913687

Shell reads each line of the file

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.