【发布时间】:2014-09-17 12:26:11
【问题描述】:
我有以下 csv 文件
more file.csv
1,yes,yes,customer1,1,2,3,4
2,no,yes,customer5,34,56,33,2
3,yes,yes,customer11
4,no,no,customer14
5,yes,no,customer15
6,yes,yes,customer21
7,no,yes,customer34
8,no,yes,customer89
编写以下(awk)行是为了操作并从 csv 中获取行并将每个元素(行)放入参数 - LINES
declare LINES=` awk -F, 'BEGIN{IGNORECASE=1} $2=="yes" {printf "\"Line number %d customer %s\"\n", $1, $4}' file.csv `
.
echo $LINES
"Line number 1 customer customer1" "Line number 3 customer customer11" "Line number 5 customer customer15" "Line number 6 customer 21”
但是当我想在参数 LINES 中打印元素的数量时,我得到 1 ??
echo ${#LINES[*]}
1
虽然实际上我需要获得 4 个元素(行)
请建议如何修复 awk 行以获得 4 个元素?
备注:
请看这个例子,当我手动编辑LINES时,元素应该是4个
declare LINES=( "Line number 1 customer customer1" "Line number 3 customer customer11" "Line number 5 customer customer15" "Line number 6 customer 21” )
echo ${#LINES[*]}
4
【问题讨论】: