This problem is so convoluted that maybe I should call it a puzzle...
On the Unix shell command line, I can convert TSV (tab-separated-values) input to org-mode table format with this perl one-liner:
perl -lpe 's/(?:^|$|\t)/|/g'
So, for example, I can write something like
<<<pipeline producing TSV rows>>> | perl -lpe 's/(?:^|$|\t)/|/g' > mytable.org
The contents of mytable.org would be a valid org-mode table, but it would not be nicely formatted.
For example, if
<<<pipeline producing TSV rows>>> produced the following
1 ABCDEFG 234567 HIJKLMNO 890123 P
...the contents of
mytable.org would be
|1|ABCDEFG| |234567|HIJKLMNO| |890123|P|
To format it nicely, I could
- set the major mode to org-mode (if it doesn't happen by default);
C-c C-c, aka
org-ctrl-c-ctrl-c-hook, which has the effect of reformatting the table so that the delimiters line up; and
- save the file;
...after which the contents of
mytable.org would look like this
| 1 | ABCDEFG | | 234567 | HIJKLMNO | | 890123 | P |
My question is, how can I perform this reformating operation from the command line, without having to start an interactive Emacs session?
More specifically, is there a way to implement a pipeline component, that uses Emacs, and that I can insert right before the output redirection
> mytable.org, like this
<<<pipeline producing TSV rows>>> | perl -lpe 's/(?:^|$|\t)/|/g' \ | format-org-table > mytable.org
...that it would achieve the same final form of
mytable.org as shown earlier? The goal here is to avoid the need to "manually" open
mytable.org with Emacs, then hit
C-c C-c, etc.