6

I've an huge org file HUGE.org with this structure:

* ID-HEAD-1 Title1 :TAG:
bla bla bla

* ID-HEAD-2 Title2 :TAG:
bla bla bla

...

* ID-HEAD-N TitleN :TAG:
bla bla bla

and I want to split HUGE.org into:

ID-HEAD-1.org
ID-HEAD-2.org
...
ID-HEAD-N.org

where the content of each ID-HEAD-i.org is:

* ID-HEAD-i Titlei :TAG:
bla bla bla

Suggestions?

  • Clarification: you mean you want to create N new files, each of which contains the sequentially numbered top-level header and its contents? – Dan May 5 '16 at 17:45
  • Yes, i want N new files! – lap May 5 '16 at 17:53
5

I use a function of my own. It moves a subtree to a new org file, and replaces it with a link to this new file. Specify the name of the file through the parameter or interactively at the prompt.

(defun org-move-tree (filename)
  "move the sub-tree which contains the point to a file,
and replace it with a link to the newly created file"
  (interactive "F")
  (org-mark-subtree)
  (let
      ((name (buffer-substring (region-beginning) (save-excursion (end-of-line) (point))))
       (xxx (buffer-substring (region-beginning) (region-end))))
    (setq name (replace-regexp-in-string "^[*]+ *" "" name))
    (delete-region (region-beginning) (region-end))
    (insert (format "[[file:%s][%s]]\n" filename name))
    (find-file-other-window filename)
    (insert xxx)
    (save-buffer)))

(provide 'org-move-tree)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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