Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to make line numbers fixed width in FFIND

May
572
4
When using FFIND /L , line numbers are rendered as a [n] where n has no leading zeroes. Is there any way to cause the line numbers to be formatted with leading zeroes, like [01] or [001]?
 
It's not too hard with Perl:
Code:
ffind /L … | perl -p -e "s/\[(\d+)\]/sprintf(q([%%%%03i]),$1)/e;"
Here the %03i (plus escaping percents-%) formats to 3 digits with leading zeros.
 
Last edited:
Thanks for the perl of wisdom. I'll try that.
...

I did try it. I downloaded and installed Strawberry Perl, and it worked after I modified the string of four consecutive percent signs down to only two of them.
 
Last edited:
This method doesn't depend on Perl.
Code:
do l in /p ffind /l /v /t"Take" readme.txt (echo.%@rereplace["\[(\d+)\](.+)",[%@format[03,\1]]\2,%l])

However, there appears to be a bug in @format. I imagine there's a way to do it using the built-in Lua interpreter too, or tpipe.
 
Here's one that uses the ridiculously complicated TPIPE
Code:
tpipe /input=readme.txt /line=1,1,0,0,-7.5d /grep=3,0,0,0,0,0,0,0,Take
 
It's kind of like programming in APL. You have no idea what the code does and it's usually easier just to rewrite it than trying to figure it out. It took me 20 minutes of futzing with the switches and various options before I figured it out.
 
Here's one that uses the ridiculously complicated TPIPE
Code:
tpipe /input=readme.txt /line=1,1,0,0,-7.5d /grep=3,0,0,0,0,0,0,0,Take
Nice one, Scott. It only took an hour to figure this out, but you can get the []s in there too.
Code:
g:\tc18> tpipe /input=readme.txt /line=1,1,0,0,-7.5d /grep=3,0,0,0,0,0,0,0,Take /replace=4,0,0,0,0,0,0,0,0,"^^(\d+?)",[$1]
[00001]  Take Command v18.0
[00012]  Greetings, and thanks for trying Take Command!
<snip>
 
I was going to suggest a regex that specified the 5 digits at the start of the line. But you got there.
 

Similar threads

Back
Top