BASH - How to extract data from a column in CSV file and put it in an array?

前端 未结 4 984
清歌不尽
清歌不尽 2020-12-28 23:07

I am learning to script in Bash.

I have a CSV file with 5 columns and 22 rows. I am interested in taking the data from the second column and put it into an array.

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-28 23:59

    Better is to use readarray. No need to mind about IFS which could have any value, and is safe from pathname expansion.

    readarray -t eCollection < <(cut -d, -f2 MyAssignment.csv)
    printf '%s\n' "${eCollection[0]}"
    

提交回复
热议问题