ohl 的来历:
有时候需要在命令提示符下找字符,但往往这是件很费力的事,然后我就想要是能高亮搜索就好了...
通过 Google,我找到了一个工具叫做 histring,示例如下:
可惜这个工具是 Linux 下的。继续搜索,可是最终没能找到 Windows 下的...
我想到另一个方法:如果有同时显示多种颜色的工具,配合 sed 来替换也是可以实现的。于是找到了 cecho 和 ansicon,但 cecho 不支持管道输入...
写了封 email 给 cecho 的作者,问能不能添加 stdin 支持,并且告诉了他 histring 这个软件。作者回复说“... histring 这个工具很有趣 ... 给我一些时间我会把 histring 移植过来(使用 PCRE)”。于是便有了 ohl 这个工具。太感谢作者了!(目前 ohl 这个工具还没有全部完成。)
ohl 使用示例:
示例 1:
- dir /b | ohl -l/black.yellow \.dll$
复制代码
[attach]5915[/attach]
示例 2:
- dir /b | ohl /red.yellow \.dll$ -l/green \.exe$
复制代码
[attach]5916[/attach]
-l 是高亮整行。匹配使用的是 PCRE 正则表达式。
可以设置变量 OHL_ATTR 来改变默认颜色(亮白色),例如 set OHL_ATTR=black.yellow。
可以在 ohl.cfg 中设置别名,例如在 ohl.cfg 中加入:
?dll
-l/black.yellow \.dll$
之后则可以使用 dir /b | ohl +dll。(如果把 ohl.exe 改成了其他名称,例如 hl.exe,则配置文件的名称相应的要变为 hl.cfg。)
-----------------------------------------------------------------------------
Output Highlighting by Jason Hood <jadoxa@yahoo.com.au>.
Version 1.00 (20 November, 2012). Freeware.
http://ohl.adoxa.cjb.net/
... | ohl [-ev]
[[+set] ["["] [-bcfilmox] [/[[B]F][:[[B]F]]...] pattern ["]"]]...
[-t|T file... | -r program [args]]
-e use ANSI escape sequences (for redirected output)
-v highlight what doesn't match
+set replace with arguments from the configuration file
[ ] begin and end a group of patterns
-b the following pattern only matches at the beginning of output
-c the following pattern will continue onto non-matching lines
-f the following pattern identifies the format of output
-i ignore case
-l the following pattern will highlight the entire line (implies -x)
-m match case (default)
-o the following pattern will only match once per line
-x the following pattern is exclusive
-t display each file (as a single stream)
-T display each file (labelling each name)
-r run program
B background color attribute (original if absent)
F foreground color attribute or color name ("foreground.background")
pattern regular expression
When an exclusive pattern matches, no further patterns are tried unless they
exist within a group.
Consecutive format patterns will apply to consecutive lines (up to 8).
The first color is for the match as a whole; the remainder apply to each
captured subpattern (up to 15). If the first is missing, it will use the
default; any others missing will use the first. An attribute may be "~" to use
the original value; "!" to invert the original's intensity; or "=" to preserve
the existing color. The default color is defined by the environment variable
OHL_ATTR; if not set, the foreground intensity of the original color will be
inverted. Please use "COLOR/?" for attribute values or "//?" for names.
File may contain wildcards, in which case directories, hidden files and
apparent binary files (a zero byte in the first Ki) are silently ignored.
http://bcn.bathome.net/s/tool/index.html?key=ohl |