Read tab-separated file line into array

前端 未结 3 980
情话喂你
情话喂你 2020-11-30 19:06

I would like to read a file into a script, line by line. Each line in the file is multiple values separated by a tab, I\'d like to read each line into an array.

Typ

3条回答
  •  青春惊慌失措
    2020-11-30 19:17

    You could also try,

    OIFS=$IFS;
    IFS="\t";
    
    animals=`cat animals.txt`
    animalArray=$animals;
    
    for animal in $animalArray
    do
        echo $animal
    done
    
    IFS=$OIFS;
    

提交回复
热议问题