对文本文件列应用算术转换 bash

Apply arithmetic transformation on a text file column bash

我有包含多列的大型 csv 文本文件,我想使用 column6column12 中的变量对 column11 应用算术转换.

转换如下:

column11=column11*1000.*column12./(8.314*(column6+273.15))

其中 .*./ 分别表示每行中值的元素乘法和除法。

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

"2015-11-11 00:00:00.00",59841,0.327,3.275,1.89275,32.048,9,2435.477,2308.886,15.03365,31.2365067891251,98.7333,253
"2015-11-11 00:00:00.10",59842,0.086,3.56975,2.20325,32.10205,10,2433.668,2298.364,15.03292,31.2299567962211,98.7473,253
"2015-11-11 00:00:00.20",59843,0.26575,3.343,1.8285,32.06717,11,2433.833,2294.418,15.03119,31.2436473758837,98.72864,253
"2015-11-11 00:00:00.30",59844,-0.1915,3.28175,1.793,32.12122,12,2433.668,2280.608,15.02593,31.2410875853554,98.7333,253
"2015-11-11 00:00:00.40",59845,-0.20375,3.447,2.0135,32.08286,13,2433.833,2276.991,15.02812,31.2245602421307,98.73796,253

理想情况下,结果将保存到同一个文件中,并通过遍历 n 个文件来重复该过程。

awkcut/pastebash 中的解决方案或一些想法会很有帮助。

你可以在没有数组的情况下编写主循环

 for f in path/to/files/*.csv
 do
    awk -F, '...' "$f" > "processed_$f"
 done