How to iterate over text file having multiple-words-per-line using shell script?

后端 未结 4 1724
南旧
南旧 2021-01-24 15:16

I know how to iterate over lines of text when the text file has contents as below:

abc  
pqr  
xyz

However, what if the contents of my text fil

4条回答
  •  既然无缘
    2021-01-24 15:47

    If the delimiter is a space then you can do:

    #!/bin/bash
    
    ALLVALUES=()
    while read line
    do
        ALLVALUES+=( $line )
    done < "/path/to/your/file"
    

    So after, you can just reference an element by ${ALLVALUES[0]} or ${ALLVALUES[1]} etc

提交回复
热议问题