![如何用 0 填充 csv 文件的空单元格并删除没有标题的单元格?](https://linux22.com/image/122931/%E5%A6%82%E4%BD%95%E7%94%A8%200%20%E5%A1%AB%E5%85%85%20csv%20%E6%96%87%E4%BB%B6%E7%9A%84%E7%A9%BA%E5%8D%95%E5%85%83%E6%A0%BC%E5%B9%B6%E5%88%A0%E9%99%A4%E6%B2%A1%E6%9C%89%E6%A0%87%E9%A2%98%E7%9A%84%E5%8D%95%E5%85%83%E6%A0%BC%EF%BC%9F.png)
我想将一个非常恶心的 csv 文件导入到 Cassandra 数据库中,其中包含空单元格和没有标题的单元格。我试过
以下命令来自linuxconfig.org:
#!/bin/bash
for i in $( seq 1 2); do
sed -e "s/^,/$2,/" -e "s/,,/,$2,/g" -e "s/,$/,$2/" -i $1
done
但当我应用它时它似乎不起作用
bash fill-empty-values.sh bouffe500.csv 0
我没有chmod +x
这么做。
这是应用脚本后的 bouffe500.csv 图像,它仍然是空字段:
当我尝试将 csv 文件导入 Cassandra 时,我认为空字段会产生问题,它回答了我:
cqlsh:k1> COPY k1.bouffe FROM 'bouffe_v2.csv' WITH HEADER=true;
Using 3 child processes
Starting copy of k1.bouffe with columns [code, additives, additives_fr, ...
...
Failed to import 1 rows: ParseError - Invalid row length 112 should be 163, given up without retries
Failed to import 7 rows: ParseError - Invalid row length 60 should be 163, given up without retries
Failed to import 1 rows: ParseError - Invalid row length 74 should be 163, given up without retries
Failed to import 2 rows: ParseError - Invalid row length 32 should be 163, given up without retries
Failed to import 5 rows: ParseError - Invalid row length 31 should be 163, given up without retries
Failed to import 1 rows: ParseError - Invalid row length 85 should be 163, given up without retries
Failed to import 1 rows: ParseError - Invalid row length 111 should be 163, given up without retries
Failed to import 3 rows: ParseError - Invalid row length 81 should be 163, given up without retries
Failed to process 499 rows; failed rows written to import_k1_bouffe.err
Processed: 499 rows; Rate: 801 rows/s; Avg. rate: 1211 rows/s
499 rows imported from 1 files in 0.412 seconds (0 skipped).
cqlsh:k1> SELECT * from bouffe;