CI grep (cont)
elseif '!entry' = 'read_match' then # finds each "pattern" in "file" and echoes the record + line num # input redirected to "!file” setvar _grep_eof finfo("!file","eof") setvar _grep_recno 0 setvar _grep_pat ups("!pattern") while setvar(_grep_recno,_grep_recno+1) <= _grep_eof and & setvar(_grep_rec, rtrim(input())) <> chr(1) do if pos(_grep_pat,ups(_grep_rec)) > 0 then echo !_grep_recno) !_grep_rec setvar _grep_matches _grep_matches+1 endif endwhile returnendif
4667 msecs …1669 records read -- 18 lines match "version”
4627 msecs …1669 records read -- 0 lines match "foo"
Notes:
- It takes approximately 4.6 seconds to read, upshift and find a string literal in a 1669 record ascii file, and approximately 123 seconds to so the same in a 45,149 record file.
- xeq grep.hpbin.sys “-in pattern file” is much faster for large files! The GREP program in HPBIN.SYS does not support CI or shell wildcarding. If you need to grep a pattern on a set of files start grep from the shell.