Page 1 of 1

Right justifying line numbers

Posted: Mon Jul 18, 2005 1:25 am
by esp2gps
TP offers a very useful regular expression facility to add line numbers in front of every line in a text file. I use this often.
Is there any way to have these numbers right justified with leading blanks? Why would this be useful you ask? Because you can number your lines, sort the text file by some criteria, remove/relocate lines that cluster together by your sort key, and then restore the remaining lines back to their original order by sorting on the line numbers. Using Block Mode, you can remove the line numbers and your text file is restored as it was minus the lines you removed.

For example, if you have up to 200 lines in a file, you have to manually put two spaces in front of the first 9 lines, then one space in front of lines 10 to 99 to have the line numbers right justified in column 3.

Posted: Mon Jul 18, 2005 7:02 am
by A bit iffy
I also need to do this all the time, but I've always used a spreadsheet up to now.

There's an easy TextPad solution, though: in the search-and-replace facility, put

Code: Select all

\i(100)
for the "Replace With", and your lines will all begin with three-digit numbers (for up to 900 lines, obviously) as they start from 100.

Posted: Mon Jul 18, 2005 8:45 am
by ben_josephs
Or \i(1000) (or whatever power of 10 you need) and then
Find what: ^.
Replace with:

[X] Regular expression
(which leaves the leading zeros in).

Posted: Mon Jul 18, 2005 5:21 pm
by esp2gps
I am always amazed at the simplicity of solutions to seemingly impossible jobs.

Very nice solutions to a workaround.

I can not imagine life without TP. I use it almost more than any other program I own.

Thanks for the suggestions

Posted: Tue Jul 19, 2005 8:10 am
by MudGuard
As noone has yet mentioned Fill Block:

Select as many columns as you want your numbers to have (block-selection), starting with the column in front of which the numbers should appear.

Go to Menu Edit - Fill Blocks

Select "With Numbers",
"Align Right" for leading blanks or "Leading Zeros" for leading zeros.
Make sure you have "insert" selected, not "replace".

Posted: Tue Jul 19, 2005 8:28 am
by A bit iffy
:D Oooh wow MudGuard! Thanks for that - I never realised "Fill Block" existed. I can see quite a few uses, and I can stop faffing around with Excel formulas. Cheers mate!

Posted: Tue Jul 19, 2005 10:15 am
by ben_josephs
MudGuard wrote:Fill Blocks

Select "With Numbers"
I'm sure I knew that once! Thanks.