Right justifying line numbers

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
esp2gps
Posts: 2
Joined: Mon Jul 18, 2005 1:13 am
Location: Woodstock, NY

Right justifying line numbers

Post 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.
User avatar
A bit iffy
Posts: 15
Joined: Thu Sep 16, 2004 1:15 pm
Location: Brighton, England

Post 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.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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).
esp2gps
Posts: 2
Joined: Mon Jul 18, 2005 1:13 am
Location: Woodstock, NY

Post 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
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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".
User avatar
A bit iffy
Posts: 15
Joined: Thu Sep 16, 2004 1:15 pm
Location: Brighton, England

Post 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!
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

MudGuard wrote:Fill Blocks

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