问题
I have IDs in the first column of data.csv with headers.
I want to skip the header and store column 1 values in the variable ids
as 102 103 104 ...
.
Pseudocode in the line ids.append($col1)
where I want to append the current row 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 output
ids=( 102 103 104 )
OS: Debian 8.5
Bash: 4.3.30(1)
回答1:
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
来源:https://stackoverflow.com/questions/40331348/how-to-parse-csv-file-for-long-row-in-bash