I have the following files and want to merge them by their unixTime field:
timestamp.csv
i2c-02.timestamp;unixTime;minValue;averageValue;maxValue
i2c-02.timestamp;2025-03-20 18:00:31.40;61230.000;61230.000;61230.000
i2c-02.timestamp;2025-03-20 18:00:34.10;61233.000;61233.000;61233.000
i2c-02.timestamp;2025-03-20 18:00:34.20;61233.000;61233.000;61233.000
i2c-02.timestamp;2025-03-20 18:00:34.30;61233.000;61233.000;61233.000
nodeid.csv
i2c-02.nodeid;unixTime;minValue;averageValue;maxValue
i2c-02.nodeid;2025-03-20 18:00:31.40;132.000;132.000;132.000
i2c-02.nodeid;2025-03-20 18:00:34.10;133.000;133.000;133.000
i2c-02.nodeid;2025-03-20 18:00:34.20;133.000;133.000;133.000
i2c-02.nodeid;2025-03-20 18:00:34.30;133.000;133.000;133.000
variable.csv
i2c-02.variable;unixTime;minValue;averageValue;maxValue
i2c-02.variable;2025-03-20 18:00:31.40;4.000;4.000;4.000
i2c-02.variable;2025-03-20 18:00:34.10;1.000;1.000;1.000
i2c-02.variable;2025-03-20 18:00:34.20;2.000;2.000;2.000
i2c-02.variable;2025-03-20 18:00:34.30;3.000;3.000;3.000
value.csv
i2c-02.value;unixTime;minValue;averageValue;maxValue
i2c-02.value;2025-03-20 18:00:31.40;1.767;1.767;1.767
i2c-02.value;2025-03-20 18:00:34.10;4.772;4.772;4.772
i2c-02.value;2025-03-20 18:00:34.20;17.029;17.029;17.029
i2c-02.value;2025-03-20 18:00:34.30;48.031;48.031;48.031
You'll notice that minValue, averageValue and maxValue are always identical inside each file, so I can keep one only. I would like to obtain merged.csv (note the comma separator this time):
unixTime,timestamp,nodeid,variable,value
2025-03-20 18:00:31.40,61230.000,132.000,4.000,1.767
2025-03-20 18:00:34.10,61233.000,133.000.1.000,4.772
2025-03-20 18:00:34.20,61233.000,133.000,2.000,17.029
2025-03-20 18:00:34.30,61233.000,133.000,3.000,48.031
I feel like I have tried everything for several hours, and will spare you all the different strategies I've used, but I think from the manual that the following command should work (except for the removal of the unwanted fields, I think I should get all fields in a single file), yet the output is incorrect:
$ mlr --csv --fs ";" join -j unixTime -f timestamp.csv \
then join -j unixTime -f nodeid.csv \
then join -j unixTime -f variable.csv value.csv
unixTime;i2c-02.variable;minValue;averageValue;maxValue;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:31.40;i2c-02.variable;1.767;1.767;1.767;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:34.10;i2c-02.variable;4.772;4.772;4.772;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:34.20;i2c-02.variable;17.029;17.029;17.029;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:34.30;i2c-02.variable;48.031;48.031;48.031;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:34.40;i2c-02.variable;1.977;1.977;1.977;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:34.70;i2c-02.variable;17.200;17.200;17.200;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:34.80;i2c-02.variable;17.140;17.140;17.140;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:34.90;i2c-02.variable;17.459;17.459;17.459;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
2025-03-20 18:00:35.00;i2c-02.variable;17.140;17.140;17.140;i2c-02.nodeid;i2c-02.timestamp;i2c-02.value
I'm afraid the first field with its periods in the strings might be the issue, but I'm not sure, and I tried cutting it in each file using mlr, but failed. Or is it because other fields have the same names between files?
What am I doing wrong? I would be very grateful for any pointers; my alternative would be to use awk but I am even worse with it and this would require more complex Bash scripting to join files in pairs and then shift the key field and fields to keep.
I am using mlr 6.13.0.
I have the following files and want to merge them by their
unixTimefield:timestamp.csvnodeid.csvvariable.csvvalue.csvYou'll notice that minValue, averageValue and maxValue are always identical inside each file, so I can keep one only. I would like to obtain
merged.csv(note the comma separator this time):I feel like I have tried everything for several hours, and will spare you all the different strategies I've used, but I think from the manual that the following command should work (except for the removal of the unwanted fields, I think I should get all fields in a single file), yet the output is incorrect:
I'm afraid the first field with its periods in the strings might be the issue, but I'm not sure, and I tried cutting it in each file using
mlr, but failed. Or is it because other fields have the same names between files?What am I doing wrong? I would be very grateful for any pointers; my alternative would be to use
awkbut I am even worse with it and this would require more complex Bash scripting to join files in pairs and then shift the key field and fields to keep.I am using
mlr6.13.0.