【发布时间】:2021-01-09 07:41:47
【问题描述】:
这是示例 csv 文件:
name,annotations,description
drgreghouse,princeton,"doctor,head"
sheldon,tbbt,"physicist,actor"
chandler,friends,"actor,comedian"
我正在尝试这样的事情,但它只读取第一个值
INPUT="$(pwd)/data.csv"
IFS=','
sed 1d $INPUT |while read name annotations description; do
echo "$name $annotations $description"
done
O/p-
drgreghouse princeton "doctor
sheldon tbbt "physicist
chandler friends "actor
预期的 O/p
drgreghouse princeton doctor,head
sheldon tbbt physicist,actor
chandler friends actor,comedian
【问题讨论】:
-
@anubhava 我已经更新了预期的 o/p
-
您可以使用
tail -n +2 file获取您的输出 -
@Kunalkishor,或者您是否只想跳过 Input_file 中的标题并保留文件中的其余行?
-
@anubhava 与
sed 1d相比并没有真正的改进。 -
IFS表示输入字段分隔符。这是read用来区分列的字符。