12 methods for linux shell to process text line by line

Source: Internet
Author: User


12 methods for linux shell to process text line by line 1. cat $ filename | while read line example: function while_read_line {cat $ filename | while read line do www.2cto.com echo "$ line ": # This line does not do anything. The return value is 0 done}
Method 2: while read $ filename from bottom example: function while_read_line_bottom {while read line do echo "$ line": done <$ filename}
Method 3: while_line_line_bottom example: function while_line_line_bottom {www.2cto.com while line # Replace read do echo "$ line": done <$ filename} with the line command}
Method 4: cat $ filename | while line = 'line' For example: function cat_while_line_line {cat $ filename | while line = 'line' do echo "$ line": done}
Method 5: cat $ filename | while line example: function while_line_LINE {www.2cto.com cat $ filename | while line do echo "$ line": done}
Method 6: while line = 'line' from the bottom example: function while_line_line_bottom {while line = 'line' do echo "$ line": done <$ filename}
Method 7: cat $ filename | while line = $ (line) for example: function while_line_line_cm {cat $ filename | while line = $ (line) do echo "$ line": done}
Method 8: while line = $ (line) from the bottom example: function while_line_line_bottom_cm {while line = $ (line) do echo "$ line" done <$ filename}
Method 9: while read line example: function while_read_line_fd {www.2cto.com exec 3 <& 0 # redirect all content to new file descriptor 3 to disable file descriptor 0 exec 0 <$ filename # standard input file descriptor 0, the standard output file descriptor is 1 and the standard error is 2. while read line #3 can be assigned to common files. Do echo "$ line" done exec 0 <& 3}
Method 10: while line = 'line' example: function while_line_line_fd {exec 3 <& 0 exec 0 <$ filename while line = 'line' do echo "$ line" done exec 0 <& 3}
Method 11: while line = $ (line) for example: function while_line_line_cm_fd {exec 3 <& 0 exec 0 <$ filename while line = $ (line) do www.2cto.com print "$ line" done exec 0 <& 3}
Method 12: while line example: function while_line_line_fd {exec 3 <& 0 exec 0 <$ filename while line do echo "$ line" done exec 0 <& 3}
 

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.