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}