while read line
do
OLD_IFS="$IFS"
IFS=","
arr=($line)
IFS="$OLD_IFS"
echo "${arr[0]} ${arr[1]}"
done < source.csv
其中IFS
(Internal Field Seprator)
叫内部域分隔符
,是shell用来拆分读入的变量所使用的环境变量,默认情况下是三种空白符。
注意:使用for循环无法处理分隔后出现的空格列问题,会破坏数据完整性
“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill
标 题:在shell中逐行处理csv文件