Home Download Buy Blog Forum Support

How I do incremental numbering of empty lines in one file?

How I do incremental numbering of empty lines in one file?

Postby attanze on Mon May 09, 2011 10:10 pm

If somebody knows how to work with ReGex, please helpme.

I have a file with some thousands of empty lines and I need to ad to every empty line an incremental number. First empty line to have number 1, second empty line to have number2, etc.
The every empty line is repeated, so I have two empty lines, and I want to insert the number just to the second empty line.

-----------

some text


more text


even more text
------------------

to transform into yhis:
-----------------

1
some text

2
more text

3
even more text
------------------

Unfortunately Regex is just to complicated and cant find any documentation regarding to this subject.
attanze
 
Posts: 16
Joined: Sun May 01, 2011 8:30 pm

Re: How I do incremental numbering of empty lines in one file?

Postby jbjornson on Tue May 10, 2011 7:18 am

Hi attanze,

The regular expression you should use is "\n\n\n" (without the quotes). Search for this with the find panel and make sure that the regular expressions option is selected. Now do a "find all" (from the find panel), which will create multiple selections. Use your arrow keys to re-position the multiple selections so the cursors are on the second empty line (right then left worked for me). Now you should have multiple selections, each one on the second of the empty lines (exactly where you want to insert the numbers).

Now you need to insert the incremental numbers into the selections, but you'll need a plugin for that. Luckily there already is one available for you: http://www.sublimetext.com/forum/viewtopic.php?f=5&t=1604&start=0. It might be easier to setup the plugin first (before you do the selection above).

Hope that helps.

Cheers,
Josh
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: How I do incremental numbering of empty lines in one file?

Postby jbjornson on Tue May 10, 2011 7:25 am

By the way, there is tons of very helpful information about regular expressions available online, for example: http://www.regular-expressions.info/. Sublime Text uses normal regular expressions so you won't find any specific documentation here.
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], mwb1100 and 22 guests