grep 语法
grep 'word' filename
grep 'string1 string2' filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName
基本的用法
在某个文件里搜索error字符串
$ grep "error" log.txt
忽略大小写搜索(-i)
$ grep -i "ErroR" log.txt
所有子目录下的搜索(-r)
$ grep -r "exception" log.txt
全字匹配搜索(-w)
如果你搜索boo,查询结果可能包含fooboo,boo123, booooom,等等,可以使用-w来限定全字匹配
$ grep -w "boo" /path/to/file
全字匹配搜索两个不同单词
$ grep -w 'word1|word2' /path/to/file
统计字符串出现的次数(-c)
$ grep -c 'word' /path/to/file
另外加-n的话, 会在结果中,列出匹配字符串的序列号,并且会列出内容
$ grep -n 'word' /path/to/file
列出“不”包含字符串的行(-v)
$ grep -v bar /path/to/file
只列出文件名(-l)
$ grep -l 'main' *.pls
高亮显示(--color)
$
grep --color oracle /etc/passwd
UNIX / Linux pipes + grep
ls -l | grep -i xyz
ls 列出当前目录下的文件和文件夹,| 是管道传递给后面的一个程序,grep再是进行模式匹配
例如:ls *.pls | grep -i --color "MM"
========EOF=========
转载请注明出处:http://blog.csdn.net/pan_tian/article/details/7685815
分享到:
相关推荐
config/autoconf.h KCONFIG_TRISTATE=/home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/tristate.config BUILDROOT_CONFIG=/home/wwt/linux_r16/lichee/out/sun8iw5p1/...
如果这命令不行,找它UNIX的进程数 SQL> select pro.spid from v$session ses,v$process pro where ses.sid=21 and ses.paddr=pro.addr; 说明:21是某个连接的sid数 然后用 kill 命令杀此进程号。 五、SQL*PLUS...
She also systematically introduces awk, sed, and grep for both UNIX and GNU/Linux . . . making this the only shell programming book you’ll ever need! New in this edition: Comprehensive coverage of...
几个等效命令test,/usr/bin/test,[],和/usr/bin/[ 7-3. 算数测试使用(( )) 7-4. test死的链接文件 7-5. 数字和字符串比较 7-6. 测试字符串是否为null 7-7. zmore 8-1. 最大公约数 8-2. 使用算术操作符 8-3. 使用&&...
几个等效命令test,/usr/bin/test,[],和/usr/bin/[ 7-3. 算数测试使用(( )) 7-4. test 死的链接文件 7-5. 数字和字符串比较 7-6. 测试字符串是否为null 7-7. zmore 8-1. 最大公约数 8-2. 使用算术操作符 8-3. 使用&&...
码头工人在Docker上尝试MPL: $ docker pull shwestrick/mpl$ docker run -it shwestrick/mpl /bin/bash...# examples/bin/primes @mpl procs 4 --构建和安装(从源代码)要求MPL仅在具有x86-64Linux上进行了测试。...
红衣主教 car·di·nal (carndi-l,kärdnl) -北美大嘴朱雀,雄性有鲜红色的羽毛。 特征 用ANSI颜色突出显示JavaScript代码以改善终端输出 主题支持,请参阅 可选地打印行号 ...cat file.js | grep
The pattern-matching examples in this chapter largely rely on grep and egrep. Chapter 4, Writing sed Scripts, begins a three-chapter section on sed. This chapter covers the basic elements of writing...
WELCOME TO TURBO C 2.0 ---------------------- This README file contains important, last minute information about Turbo C 2.0.....DOC file on the COMMAND LINE/UTILITIES disk also answers many common ...
WELCOME TO TURBO C 2.01 ----------------------- This README file contains important, last minute information about Turbo C 2.01.....DOC file on the COMPILER/UTILITIES disk also answers many common ...
How to Use this Book How This Book Is Organized Conventions Used in This Book Using Code Examples We'd Like to Hear from You Chapter 1. Customizing the User Environment ...