Wednesday, March 16, 2016

special merging of files

Hi all,

I have a number n of text files (var1, var2, var3, ..., varn).
Each file has an unknown number of lines (different from file to file). Each line
contains information of the kind
date time numerical_value
and follows the format
dd/MM/YYYY hh:mm:ss value
where
dd - day (01--31)
MM - month (01--12)
YYYY - year
hh - hour (0--23)
mm - minute (0:59)
ss - (0:59)
value - numerical value.

The time "column" is not necessarily the same in all the files.

Using vim (or any other tool) is it possible to merge in an expedite way all
the n files into a single file so that:
- the numerical values contained initially in the n files are written in
different columns of the single final file, ie, the new file has the format
dd/MM/YYYY hh:mm:ss var1 var2 var3 ........ varn
- the final file should present the entries in chronological order
- when there isn't information from a certain file for the time instant being
processed, the corresponding place should be left empty.


Example: 3 initial files

var1:
14/03/2016 13:25:15 99.2
15/03/2016 19:43:00 97.4
15/03/2016 21:23:30 98.1
15/03/2016 21:25:30 98.1
16/03/2016 12:33:45 99.5
16/03/2016 21:23:30 97.8

var2:
14/03/2016 13:25:15 500.5
15/03/2016 21:25:30 500.4
15/03/2016 21:25:45 501.3
16/03/2016 12:33:45 500.7
16/03/2016 15:00:45 501.1
16/03/2016 21:23:30 502.2

var3:
14/03/2016 13:25:15 3.3
14/03/2016 16:00:45 3.3
15/03/2016 19:43:00 3.5
15/03/2016 21:25:30 3.3
16/03/2016 15:00:45 3.4
16/03/2016 21:23:30 3.4

This 3 files should produce the following file:

date time var1 var2 var3
14/03/2016 13:25:15 99.2 500.5 3.3
14/03/2016 16:00:45 3.3
15/03/2016 19:43:00 97.4 3.5
15/03/2016 21:23:30 98.1
15/03/2016 21:25:30 98.1 500.4 3.3
15/03/2016 21:25:45 501.3
16/03/2016 12:33:45 99.5 500.7
16/03/2016 15:00:45 501.1 3.4
16/03/2016 21:23:30 97.8 502.2 3.4

I would appreciate any possible help.
In case it helps, I run vim in a Linux machine.
Thank you very much,
Natércia

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: