grep linux

[root@node4 ~]# grep  --help

Usage: 

     grep [OPTION]... PATTERN [FILE] ...

Search for PATTERN in each FILE or standard input.

Example: 

      grep -i 'hello world' menu.h main.c

Regexp selection and interpretation:使用参数和解释

  -e, --regexp=PATTERN      use PATTERN as a regular expression  

  -E, --extended-regexp     PATTERN is an extended regular expression

  -e<范本样式>或--regexp=<范本样式>   指定字符串做为查找文件内容的范本样式。
  -E或--extended-regexp   将范本样式为延伸的普通表示法来使用。

  -F, --fixed-strings       PATTERN is a set of newline-separated strings
  -G, --basic-regexp        PATTERN is a basic regular expression
  -P, --perl-regexp         PATTERN is a Perl regular expression
  -f, --file=FILE           obtain PATTERN from FILE

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

  -w, --word-regexp         force PATTERN to match only whole words
  -x, --line-regexp         force PATTERN to match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline
Miscellaneous: 其他参数
  -s, --no-messages         suppress error messages

  -v, --invert-match        select non-matching lines 显示不匹配的行

  -V, --version             print version information and exit
      --help                display this help and exit
      --mmap                use memory-mapped input if possible
Output control:
  -m, --max-count=NUM       stop after NUM matches
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines  显示匹配行及行号

      --line-buffered       flush output on every line

  -H, --with-filename       print the filename for each match  显示文件名
  -h, --no-filename         suppress the prefixing filename on output  不显示文件名
      --label=LABEL         print LABEL as filename for standard input
  -o, --only-matching       show only the part of a line matching PATTERN
  -q, --quiet, --silent        suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE
                            TYPE is 'binary', 'text', or 'without-match'

  -a, --text                equivalent to --binary-files=text    将 binary 文件以 text 文件的方式搜寻数据
   -I                          equivalent to --binary-files=without-match  

  -d, --directories=ACTION  how to handle directories
                            ACTION is 'read', 'recurse', or 'skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets
                            ACTION is 'read' or 'skip'
  -R, -r, --recursive       equivalent to --directories=recurse
      --include=PATTERN     files that match PATTERN will be examined
      --exclude=PATTERN     files that match PATTERN will be skipped.
      --exclude-from=FILE   files that match PATTERN in FILE will be skipped.
  -L, --files-without-match only print FILE names containing no match 只列出不匹配的文件名
  -l,  --files-with-matches  only print FILE names containing matches  只列出匹配的文件名
  -c, --count               only print a count of matching lines per FILE  只列出每个文件匹配行的数量
  -Z, --null                print 0 byte after FILE name    列出匹配文件的大小
Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context

  -C, --context=NUM         print NUM lines of output context     计算找到'搜寻字符串' 的次数

  -NUM                      same as --context=NUM

      --color[=WHEN],
      --colour[=WHEN]       use markers to distinguish the matching string   可以将找到的关键词部分加上颜色

                            WHEN may be `always', `never' or `auto'.

  -U, --binary              do not strip CR characters at EOL (MSDOS)
  -u, --unix-byte-offsets   report offsets as if CRs were not there (MSDOS)
`egrep' means `grep -E'.  `fgrep' means `grep -F'.
With no FILE, or when FILE is -, read standard input.  If less than
two FILEs given, assume -h.  Exit status is 0 if match, 1 if no match,
and 2 if trouble.
Report bugs to <bug-grep@gnu.org>.

[root@node4 ~]#

过滤出多个关键字:

grep -E '123|abc' filename  // 找出文件(filename)中包含123或者包含abc的行
egrep '123|abc' filename    //用egrep同样可以实现
awk '/123|abc/'  filename // awk 的实现方式


grep -Ei "error|ORA-"  xxxxx.log





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值