如何用 0 填充 csv 文件的空单元格并删除没有标题的单元格?

如何用 0 填充 csv 文件的空单元格并删除没有标题的单元格?

我想将一个非常恶心的 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 图像,它仍然是空字段:

应用脚本后的 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;

相关内容