How to use 'readarray' in bash to read lines from a file into a 2D array

后端 未结 6 1751
旧时难觅i
旧时难觅i 2021-02-04 06:35

Let\'s say I have a text file \'demo.txt\' who has a table in it like this:

1 2 3    
4 5 6    
7 8 9    

Now, I want to read each line separat

6条回答
  •  醉酒成梦
    2021-02-04 07:08

    readarray rows < demo.txt                                           
    
    for row in "${rows[@]}";do                                                      
      row_array=(${row})                                                            
      first=${row_array[0]}                                                         
      echo ${first}                                                                 
    done 
    

提交回复
热议问题