pgrep - python做的小工具

一直感慨AIX上面的grep命令的一个特性比GNU grep要好得多。
它可以列出包含搜索内容的段落,而不仅仅是行。
这尤其对类似 db2 list db directory 这样的命令结果有效。

但是Windows, Linux上面都没有拥有这个能力的工具。

初学python,刚好需要练习,于是自己做了一份。也算是自给自足了。
既然是搜索段落( Paragraph),就起了个名字,叫 pgrep。

可以从这里下载,下载完了记得改名字。
http://download.csdn.net/source/164755

为了方便广大没有安装python的Windows用户(也为了自己运行快一些),做成了一个Windows下的安装版本。
http://download.csdn.net/source/296203

使用帮助如下(为了走向世界,做成了英文的,好累…… ^_^;  ):
------------------------------------
pgrep v1.00.x071127
by Programus (programus@gmail.com)
------------------------------------
An open source and free command line grep like tool.
It prints out the paragraphs which contains the pattern instead of lines.

Usage: pgrep [OPTION]... PATTERN [FILE] ...
<If you run from source code> python pgrep [OPTION]... PATTERN [FILE] ...

Search for PATTERN in each FILE or standard input and output a paragraph separated by separator.
Example: python pgrep.py -i 'hello world' menu.h main.c

OPTIONS:
-c, --count
        Suppress normal output; instead print a count of matching lines for each input file.
        With the -v, --invert-match option, count non-matching lines.
-e, --regexp=PATTERN
        Use pattern as the pattern; useful to protect patterns beginning with a -.
-f, --file=FILE
        Obtain patterns from file, one per line.  The empty file contains zero patterns, and therefore matches nothing.
-h, --help
        Print this help
-i, --ignore-case
        Ignore case distinctions in both the pattern and the input files.
-l, --files-with-matches
        Suppress normal output; instead print the name of each input file from which output would normally have been printed.
        The scanning of every file will stop on the first match.
-p, --separator=SEPARATOR
        Specify a separator. The default separator is '/n/s*/n'.
-v, --invert-match
        Invert the sense of matching, to select non-matching parts.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值