使用bash处理CSV数据

我有一个包含几行和几列的CSV文件,有些行有4列,有些行有5列。我想添加到具有4列的列中,再增加一列,以便所有行都具有5列。我必须添加的信息必须在第三行或末尾。 CSV文件如下所示:

name;ip;supplier;os;manufact

这怎么能在bash中完成?

xunyanli 回答:使用bash处理CSV数据

您可以使用 async show({ request }){ const { page,pageSize } = request.get(); const filter = request.input('filter') const bIds = await BookUnit .query() .where('book_id',request.params.id) .ids() if (filter) { if (filter.search("description") !== -1) { let description = filter.match(/(?<=description~contains~').*?(?=')/) questions.where('description','ilike','%' + description[0] + '%') //Add new condition } if (filter.search('unit') !== -1) { let unit = filter.match(/(?<=unit~contains~').*?(?=')/) bIds.where('unit','=',unit[0]) //Add new condition } } const questions = Question .query() .whereIn('book_unit_id',bIds) .with('book_unit') if (filter) { if (filter.search("description") !== -1) { let description = filter.match(/(?<=description~contains~').*?(?=')/) questions.where('description','%' + description[0] + '%') //Add new condition } } return await questions.paginate(page,pageSize) //Now query is executed but now i have: > bIds.where is not a function",@Edit new tentative: async show({ request }){ const { page,request.params.id) .ids() const questions = Question .query() .with('book_unit',(builder) => { if(filter){ if (filter.search('unit') !== -1) { let unit = filter.match(/(?<=unit~contains~').*?(?=')/) builder.where('unit',unit[0]) //Add new condition } } }) .whereIn('book_unit_id',bIds) //Filtros if (filter) { if (filter.search("description") !== -1) { let description = filter.match(/(?<=description~contains~').*?(?=')/) questions.where('description',pageSize) //Now query is executed } [![enter image description here][1]][1] 拆分CSV,然后输出所需的列数。

read

例如,包含以下内容的test.csv:

cat test.csv | while read line; do
  IFS=\; read -ra COL <<< "$line"
  echo "${COL[0]};${COL[1]};${COL[2]};${COL[3]};${COL[4]};"
done

上面的脚本输出:

1;2;3;4
1;2;3;4;5
1;2;3;4;
1;2;3;4;5;
本文链接:https://www.f2er.com/3078445.html

大家都在问