How to make line numbers fixed width in FFIND

May 29, 2008
540
3
Groton, CT
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:
May 29, 2008
540
3
Groton, CT
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:

samintz

Scott Mintz
May 20, 2008
1,336
12
Solon, OH, USA
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.
 

samintz

Scott Mintz
May 20, 2008
1,336
12
Solon, OH, USA
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
 

samintz

Scott Mintz
May 20, 2008
1,336
12
Solon, OH, USA
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.
 
May 20, 2008
9,426
63
Syracuse, NY, USA
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>