0

now I have a file of a lot of such structure:

* one
:PROPERTIES:
:CUSTOM_ID: one
:END:
* one
:PROPERTIES:
:CUSTOM_ID: one
:END:
* one
:PROPERTIES:
:CUSTOM_ID: one
:END:
* one
:PROPERTIES:
:CUSTOM_ID: one
:END:
* two
BROWN FOX
* two
BROWN FOX
* two
BROWN FOX
* two
BROWN FOX

how can I revert it back so there is only one of every entity?

4
  • How is this related to Tramp? Commented Feb 19 at 9:48
  • Michael Albinus I believe this behavior is due to error I recieved with Tramp, it said something like "decoding ..." but I'm not sure so I've put a question sign respectively Commented Feb 19 at 10:01
  • If you want to let it investigate from Tramp pov, pls give a recipe. Otherwise, if you want only know how to repair the org-mode file, you might remove the tramp tag from your question. It wouldn't be related then. Commented Feb 19 at 11:36
  • Unless you have a backup (one you took manually, one that Emacs took atomatically or one that your version control system provides), then your only recourse is to manually delete the duplicates.
    – NickD
    Commented Feb 19 at 19:23

1 Answer 1

0

I have come up with a better-than-nothing solution: a python script

filename = ""
output_filename = ""


with open(filename, mode="r") as f:
    tmp = f.read()


blocks = tmp.split('\n*')


output_list = []
for block in blocks:
    if block not in output_list:
        output_list.append(block)

with open(output_filename, mode="w") as f:
    f.write("\n*".join(output_list))

I hope this helps someone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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