- May
- 13,190
- 180
In another thread I mentioned
for finding strings matching a regex in a file or a pipe. It's pretty fast; it lacks the ability to invert the search (return lines that don't match); and you can only specify case-insensitivity in the regex itself (with (?i)).
Here's another (source far below), TGREP, which uses TPIPE. It's written as a library function but could could be used as a BTM after commenting/removing the first and last lines. It allows inverting the search, specifying case-insensitivity outside the regex, and it's slow.
Here are two speed comparisons, in/not in a pipe.
And here's TGREP_SRC.BTM. Suggestions for improvement will be welcomed.
Code:
d:\data\tcclibrary> alias mygrep
ffind /v /k /m /e%1
for finding strings matching a regex in a file or a pipe. It's pretty fast; it lacks the ability to invert the search (return lines that don't match); and you can only specify case-insensitivity in the regex itself (with (?i)).
Here's another (source far below), TGREP, which uses TPIPE. It's written as a library function but could could be used as a BTM after commenting/removing the first and last lines. It allows inverting the search, specifying case-insensitivity outside the regex, and it's slow.
Code:
d:\data\tcclibrary> tgrep /?
Syntax: TGREP [/i (insensitive)] [/v (invert)] regex [filename]
Here are two speed comparisons, in/not in a pipe.
Code:
d:\data\tcclibrary> timer /q & (echo foo | mygrep "(?i)FOO") & timer
foo
Timer 1 off: 11:22:48 Elapsed: 0:00:00.089
d:\data\tcclibrary> timer /q & (echo foo | tgrep /i "FOO") & timer
foo
Timer 1 off: 11:22:53 Elapsed: 0:00:00.419
d:\data\tcclibrary> timer /q & (mygrep "Fire|Prox" %_ininame) & timer
ProxyPort=80
FirewallType=None
FirewallPort=0
Timer 1 off: 11:33:40 Elapsed: 0:00:00.007
d:\data\tcclibrary> timer /q & (tgrep "Fire|Prox" %_ininame) & timer
ProxyPort=80
FirewallType=None
FirewallPort=0
Timer 1 off: 11:33:41 Elapsed: 0:00:00.337
And here's TGREP_SRC.BTM. Suggestions for improvement will be welcomed.
Code:
tgrep {
setlocal
if "%1" == "" .or. "%1" == "/?" ^
(echo ^r^nSyntax: TGREP [/i (insensitive)] [/v (invert)] regex [filename] & quit)
set case=1
set type=3
if "%1" == "/i" (set case=0 & shift)
if "%1" == "/v" (set type=4 & shift)
if "%1" == "/i" (set case=0 & shift)
if "%1" != "" (set regex=%1) else (echoerr tgrep: Missing regex & quit)
iff %_pipe == 0 then
if "%2" == "" (echoerr tgrep: No file specified & quit)
if not exist %2 (echoerr tgrep: The specified file does not exist (%2) & quit)
set filespec=/input=%2
endiff
tpipe %filespec /grep=%type,0,0,%case,0,0,0,0,%regex
}