Welcome!

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

SignUp Now!

FFIND and multi-line regular expressions

May
12,846
164
I never knew (GRRRR!) that FFIND can handle multi-line regular expressions (so can Gnu GREP.EXE, which I also didn't know). Either one would have come in handy many times over many years. Rex, is it by design and reliable? If so, the help should brag about it!

In testing I randomly wrote one of 4 lines, 32768 times, to a file. The lines were "My", "dog", "has", and "fleas.". I wondered how often those lines appeared consecutively (probability predicts 128 on average). This did it.

Code:
v:\> ffind /u /v /e"My\r\ndog\r\nhas\r\nfleas" doggy.txt | tail /n5
  125 lines in      1 file

GREP.EXE too.

Code:
v:\> g:\gnu\grep -c -P "My\ndog\nhas\nfleas." doggy.txt
125

I like how FFIND (and GREP) counts the matches (instead of the 500 lines that include the matches).

You can also do it with FFIND /T. And while I have no particular preference, GREP.EXE, FFIND /T, and FFIND /E differ in an interesting way.

Code:
v:\> ffind /v /k /m /e"My\r\ndog\r\nhas\r\nfleas" doggy.txt | tail /n4
My
My
My
My

v:\> ffind /v /k /m /t"My^r^ndog^r^nhas^r^nfleas" doggy.txt | tail /n4
fleas.
fleas.
fleas.
fleas.

v:\> g:\gnu\grep -P "My\ndog\nhas\nfleas." doggy.txt | tail /n4
My
dog
has
fleas.
 
It also works with /T and in pipes ... also by design and reliable? The /E version is much faster!

Code:
v:\> timer & (do i=1 to 100 (ffind /v /k /m /e"My\r\ndog\r\nhas\r\nfleas" doggy.txt)) > nul & timer
Timer 1 on: 23:40:38
Timer 1 off: 23:40:39  Elapsed: 0:00:01.40

v:\> timer & (do i=1 to 100 (ffind /v /k /m /t"My^r^ndog^r^nhas^r^nfleas" doggy.txt)) > nul & timer
Timer 1 on: 23:42:39
Timer 1 off: 23:42:44  Elapsed: 0:00:04.40
 

Similar threads

Back
Top