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