2

I have following text which are expressed in level 5

***** It's better to be first than it is to be better.
***** The basic issue in marketing is creating a category you can be first in. It’s the law of leadership: It’s
      better to be first than it is to be better.
***** It’s much easier to get into the mind first than to try to convince someone you have a better product than the
      one that did get there first.

........

I want to change into list

00001 It's better to be first than it is to be better.
00002 The basic issue in marketing is creating a category you can be first in. It’s the law of leadership: It’s
      better to be first than it is to be better.
00003 It’s much easier to get into the mind first than to try to convince someone you have a better product than the
      one that did get there first.

Is there any quick way to do that?

3
  • 1
    Does this query replace regexp get what you want?: Search for "^\*+\(\s-+.*\)" and replace with "\,(format "%05d" \#)\1". Mar 22 '16 at 15:35
  • 1
    It can get even more fancy by changing the replacement expression to "\,(format (concat "%0" (number-to-string (org-current-level)) "d") \#)\1" :) Mar 22 '16 at 15:44
  • Cool! I'll convert that to an answer. Mar 22 '16 at 16:09
2

You can use the in-built query-replace-regexp function to do this kind of text manipulation. By default, it is bound to C-M-%.

So you would do C-M-%,

  • enter "^\*+\(\s-+.*\)" in the Query replace regexp: field, and
  • "\,(format (concat "%0" (number-to-string (org-current-level)) "d") (1+ \#))\1" in the with: field.

Above will convert

* abc
** def
*** ghi
**** jkl
***** mno
****** pqr
******* stu
******** vwx
********* yz

to

1 abc
02 def
003 ghi
0004 jkl
00005 mno
000006 pqr
0000007 stu
00000008 vwx
000000009 yz

NOTE: If you want to deal with only level-5 headings, you can have the search regexp and replace strings as "^\*\{5\}\(\s-+.*\)" and "\,(format "%05d" (1+ \#))\1".


When applying either of the above two solutions on your example, the result is the exact same as you have in the question.

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.