在大型CSV文件中搜索和修改列

时间:2014-03-12 07:53:17

标签: windows perl unix sed awk

我有一些大型CSV文件,格式如下(以逗号分隔)

2014.03.11 14:59:59.146,67.1547,67.15507,0.02,0.02
2014.03.11 14:59:59.206,67.15405,67.15437,0.02,0.02
2014.03.11 14:59:59.506,67.15552,67.15589,0.02,0.02
2014.03.11 14:59:59.707,67.15581,67.15616,0.02,0.02

现在我想完成这项任务。

  • 多数100到第2列和第3列

结果应该是

2014.03.11 14:59:59.146,6715.47,6715.507,0.02,0.02
2014.03.11 14:59:59.206,6715.405,6715.437,0.02,0.02
2014.03.11 14:59:59.506,6715.552,6715.589,0.02,0.02
2014.03.11 14:59:59.707,6715.581,6715.616,0.02,0.02

非常感谢帮助。感谢

2 个答案:

答案 0 :(得分:4)

awk应该:

awk '{$2*=100;$3*=100}1' FS=, OFS=, file
2014.03.11 14:59:59.146,6715.47,6715.51,0.02,0.02
2014.03.11 14:59:59.206,6715.4,6715.44,0.02,0.02
2014.03.11 14:59:59.506,6715.55,6715.59,0.02,0.02
2014.03.11 14:59:59.707,6715.58,6715.62,0.02,0.02

您可以使用$2=$2*100$2*=100将列乘以100

答案 1 :(得分:1)

perl -F/,/ -lape "$F[$_] *= 100 for (1,2); $_ = join',', @F;" < input.csv > output.csv