| Start | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Looping through a file line by line If file may not include a newline at the end, then: |
||||||||||||
| Looping through the output of a command field by field Let's assume that the field separator is Or with a pipe: |
||||||||||||
Read lines of a file into an array Or with a loop: |
||||||||||||
Read lines of a string into an array or with a loop: |
||||||||||||
Looping through a string line by line or |
||||||||||||
Looping through the output of a command line by line or with a pipe: |
||||||||||||
| Read a file field by field Let's assume that the field separator is For a content: The output is: |
||||||||||||
| Read a string field by field Let's assume that the field separator is Output: |
||||||||||||
| Read fields of a file into an array Let's assume that the field separator is |
||||||||||||
| Read fields of a string into an array Let's assume that the field separator is Output: |
||||||||||||
Reads file (/etc/passwd) line by line and field by field In unix password file, user information is stored line by line, each line consisting of information for a user separated by colon (???? character. In this example while reading the file line by line, the line is also split into fields using colon character as delimiter which is indicated by the value given for IFS. Sample input Sample Output To read line by line and have the entire line assigned to variable, following is a modified version of the example. Note that we have only one variable by name line mentioned here. Sample Input Sample Output Parameters
|
Read Article
https://develop.horje.com/learn/1434/reference