读书人

Grep应用心得

发布时间: 2013-02-15 15:46:56 作者: rapoo

Grep使用心得
Usage: grep [OPTION]... PATTERN [FILE] ...

-C, --context=NUM print NUM lines of output context
在查询日志时非常有用,尤其是那种日志信息写在连续几行的。


-e, --regexp=PATTERN use PATTERN as a regular expression
一般查询大家都比较熟悉,另外grep还支持正则查询,比如要查含有“[766]”的可以:
grep -e "\[766\]" filename

-w, --word-regexp force PATTERN to match only whole words

-x, --line-regexp force PATTERN to match only whole lines

-v, --invert-match select non-matching lines 非关系

-E, --extended-regexp PATTERN is an extended regular expression 或关系
[root@localhost log]# grep -E "1360XX|1391XX" down.log

-i, --ignore-case ignore case distinctions
忽略大小写

ps:
指定某一字段符合什么字符串则显示,如第二个字符串为"[2004_10_10_0013]" 则显示
[root@localhost log]# awk '{if($2== "[2004_10_10_0013]") print $0}' mo_yl.log

$0整个纪录 $1字段1。。。。

读书人网 >开源软件

热点推荐