如何向 CSV 文件中添加所有行都包含相同文本的新列

如何向 CSV 文件中添加所有行都包含相同文本的新列

这是我的输入文件的示例:

22/12/1999,conductivity,42,uS/cm
06/01/2000,conductivity,22,uS/cm
26/01/2000,conductivity,26,uS/cm
09/02/2000,conductivity,32,uS/cm
23/02/2000,conductivity,33,uS/cm

我想重新格式化它,以便它与另一个数据库匹配。第一列需要COMPTON在所有行中显示,第六列需要显示PRECIPITATION,第七列需要显示NOT APPLICABLE

我可能需要使用某些awk功能但不确定。

答案1

使用 Miller (https://github.com/johnkerl/miller)你可以运行

mlr --csv -N put '$a="COMPTON";$b="PRECIPITATION";$c="NOT APPLICABLE"' then reorder -f a  input.csv

具有

+---------+------------+--------------+----+-------+---------------+----------------+
| COMPTON | 22/12/1999 | conductivity | 42 | uS/cm | PRECIPITATION | NOT APPLICABLE |
| COMPTON | 06/01/2000 | conductivity | 22 | uS/cm | PRECIPITATION | NOT APPLICABLE |
| COMPTON | 26/01/2000 | conductivity | 26 | uS/cm | PRECIPITATION | NOT APPLICABLE |
| COMPTON | 09/02/2000 | conductivity | 32 | uS/cm | PRECIPITATION | NOT APPLICABLE |
| COMPTON | 23/02/2000 | conductivity | 33 | uS/cm | PRECIPITATION | NOT APPLICABLE |
+---------+------------+--------------+----+-------+---------------+----------------+

相关内容