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

前端 未结 4 980
清歌不尽
清歌不尽 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-29 00:04

    i like to use awk. First split based on , delimiter and take required column values into array.

    abc=($(tail -n +1 MyAssignment.csv | awk -F ',' '{print $2;}'))
    echo ${abc[1]}
    

    Index start from 1. If the file contains headers, replace +1 with +2 to ignore headers.

提交回复
热议问题