1. grep (global search regular expression(re) and print out the line,全面搜尋正規表示式並把行列印出來)是一種強大的文字搜尋工具,它能使用正規表示式搜尋文字,並把匹配的行列印出來。
2. 主要問題還是在正則式的應用上
可以參考用到的 正規表示式
3. --help看細節:
example: grep -i 'hello world' menu.h main.c
regexp selection and interpretation:
-e, --extended-regexp pattern is an extended regular expression (ere)
-f, --fixed-strings pattern is a set of newline-separated fixed strings
-g, --basic-regexp pattern is a basic regular expression (bre)
-p, --perl-regexp pattern is a perl regular expression
-e, --regexp=pattern use pattern for matching
-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
-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
-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=file_pattern search only files that match file_pattern
--exclude=file_pattern skip files and directories matching file_pattern
--exclude-from=file skip files matching any file pattern from file
--exclude-dir=pattern directories that match pattern will be skipped.
-l, --files-without-match print only names of files containing no match
-l, --files-with-matches print only names of files containing matches
-c, --count print only a count of matching lines per file
-t, --initial-tab make tabs line up (if needed)
-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 highlight the matching strings;
when is `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'.
參考:1. http://man.chinaunix.net/newsoft/grep/open.htm
2.
Linux命令學習之grep命令
格式 grep options pattern file grep命令堆在輸入或指定的檔案中查詢包含匹配指定模式的字元的行。grep的輸出就是包含了匹配模式的行。原始檔內容 ocetl yxddn65 demo more file12 46315 9510 ocetl yxddn65 demo gr...
Linux學習之grep命令
參考資料 root www dmesg grep n a3 b2 color auto eth 245 pci setting irq 10 as level triggered 246 acpi pci interrupt 0000 00 0e.0 a link lnkb 247 eth0 rea...
Linux中grep命令學習
grep acinv color auto 搜尋字串 filename 選項與引數 a 將 binary 檔案以 text 檔案的方式搜尋資料 c 計算找到 搜尋字串 的次數 i 忽略大小寫的不同,所以大小寫視為相同 n 順便輸出行號 v 反向選擇,亦即顯示出沒有 搜尋字串 內容的那一行!將 etc...