windows 10, emacs 26.1

Suppose in my.org I has text:

OwnerKey    OrganizationName    GUID

1111350    My TV    aaaaa561-4194-4441-9FA5-4D712B2659EE
3333363    My TV    Abbbbb61-4cccccc41-9ddddddd12B2659EE
4444445    My TV    A3B8F561-4194-4441-9eeeeeeeeeee659EE
5555579    UF-energ electr pers    1111CFD2-Bf444ffff-A985-CB060075D9F3
6666631    Ingineric SRL  36A92222233A2-4A91-9826-7DD4F444442D

I need to auto convert them to table.

  1. select whole text
  2. in menu tbl->Convert region

Result:

| OwnerKey | OrganizationName | GUID   |                                      |                                      |
|          |                  |        |                                      |                                      |
|  1111350 | My               | TV     | aaaaa561-4194-4441-9FA5-4D712B2659EE |                                      |
|  3333363 | My               | TV     | Abbbbb61-4cccccc41-9ddddddd12B2659EE |                                      |
|  4444445 | My               | TV     | A3B8F561-4194-4441-9eeeeeeeeeee659EE |                                      |
|  5555579 | UF-energ         | electr | pers                                 | 1111CFD2-Bf444ffff-A985-CB060075D9F3 |
|  6666631 | Ingineric        | SRL    | 36A92222233A2-4A91-9826-7DD4F444442D |                                      |

But it not correct. It must smt like this:

| OwnerKey | OrganizationName     | GUID                                 |
|----------+----------------------+--------------------------------------|
|  1111350 | My TV                | aaaaa561-4194-4441-9FA5-4D712B2659EE |
|  3333363 | My TV                | Abbbbb61-4cccccc41-9ddddddd12B2659EE |
|  4444445 | My TV                | A3B8F561-4194-4441-9eeeeeeeeeee659EE |
|  5555579 | UF-energ electr pers | 1111CFD2-Bf444ffff-A985-CB060075D9F3 |
|  6666631 | Ingineric SRL        | 36A92222233A2-4A91-9826-7DD4F444442D |

I suppose that is because in text has spaces. E.g in "My TV".

But how I can fix this?

  • Are the fields separated by TAB? In this case, C-u C-u before C-c | will use TAB as separator. Check documentation for org-table-convert-region. – Juancho Dec 1 at 23:14
  • 1
    Or use C-u 2 as prefix to separate on 2 or more spaces or TAB. – Juancho Dec 1 at 23:16
  • You can use M-x whitespace-mode to see what whitespace characters separate the table columns. – Tobias Dec 2 at 9:28
  • @Juancho Fields not separate by TAB. It's separate by spaces. – Alexei Dec 2 at 11:02

You can control de behavior of org-table-convert-region by giving a numeric prefix before calling. I've quoted part of the documentation below.

Normally, this function works in automatic mode (nil). You can choose to use comma, TAB or regexp by prefixing with 1, 2 or 3 C-us.

Or, if you prefix with a number (e.g. C-2 or C-u 2), it uses those many spaces for separating columns.

In your example, with an argument of 2, it works perfectly since all columns are separated by at least 2 spaces.

(org-table-convert-region BEG0 END0 &optional SEPARATOR)

...

SEPARATOR specifies the field separator in the lines. It can have the following values:

(4) Use the comma as a field separator

(16) Use a TAB as field separator

(64) Prompt for a regular expression as field separator

integer When a number, use that many spaces, or a TAB, as field separator

regexp When a regular expression, use it to match the separator

nil When nil, the command tries to be smart and figure out the separator in the following way: - when each line contains a TAB, assume TAB-separated material - when each line contains a comma, assume CSV material - else, assume one or more SPACE characters as separator.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.