How to parse a CSV file for a long line in Bash?

I have identifiers in the first column of data.csv with headers. I want to skip the header and save the values โ€‹โ€‹of column 1 in the ids variable as 102 103 104 ... Pseudocode in line ids.append($col1) , where I want to add the current line value to the end of the line with a space

 # http://stackoverflow.com/a/4286841/54964 while IFS=, read col1 do ids.append($col1) # Pseudocode done < data.csv 

data.csv

 102 103 104 

Expected Result

 ids=( 102 103 104 ) 

OS: Debian 8.5
Bash: 4.3.30 (1)

0
bash bash4
30 Oct. '16 at 16:49
source share
1 answer

With GNU bash and GNU tail:

 #!/bin/bash array=() while IFS=, read -r col1 coln do array+=("$col1") # append $col1 to array array done < <(tail -n +2 data.csv) declare -p array 
+2
Oct 30 '16 at 16:59
source share



All Articles