grep '[A-Z]' list Lines from list containing a capital letter
grep '[0-9]' data Lines from data containing a number
grep '[A-Z]...[0-9]' list Lines from list containing five-character patterns that start with a capital letter and end with a digit
grep '/.pic$' filelist Lines from filelist that end in .pic
$ grep shell *
cmdfiles:shell that enables sophisticated
ed.cmd:files, and is independent of the shell.
ed.cmd:to the shell, just type in a q.
grep.cmd:occurrence of the word shell:
grep.cmd:$ grep shell *
grep.cmd:every use of the word shell.
$
-i表示忽略大小写
grep –i 'the' intro
-v表示查找不包含此字符串的行
$ grep -v 'UNIX' intro Print all lines that don't contain UNIX
Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
environment that promoted efficient program
development.
$
-l表示列出包含此字符串的文件名 $ grep -l 'Move_history' *.c List the files that contain Move_history
exec.c
makemove.c
testch.c
$
$ grep -l 'Move_history' *.c | wc -l
3
$
-n打印所包含字符串的行数
$ grep -n 'Move_history' testch.c Precede matches with line numbers
13:GLOBAL MOVE Move_history[100] = {0};
197: Move_history[Number_half_moves-1].from = move.from;
198: Move_history[Number_half_moves-1].to = move.to;
$
grep '[0-9]' data Lines from data containing a number
grep '[A-Z]...[0-9]' list Lines from list containing five-character patterns that start with a capital letter and end with a digit
grep '/.pic$' filelist Lines from filelist that end in .pic
$ grep shell *
cmdfiles:shell that enables sophisticated
ed.cmd:files, and is independent of the shell.
ed.cmd:to the shell, just type in a q.
grep.cmd:occurrence of the word shell:
grep.cmd:$ grep shell *
grep.cmd:every use of the word shell.
$
-i表示忽略大小写
grep –i 'the' intro
-v表示查找不包含此字符串的行
$ grep -v 'UNIX' intro Print all lines that don't contain UNIX
Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
environment that promoted efficient program
development.
$
-l表示列出包含此字符串的文件名 $ grep -l 'Move_history' *.c List the files that contain Move_history
exec.c
makemove.c
testch.c
$
$ grep -l 'Move_history' *.c | wc -l
3
$
-n打印所包含字符串的行数
$ grep -n 'Move_history' testch.c Precede matches with line numbers
13:GLOBAL MOVE Move_history[100] = {0};
197: Move_history[Number_half_moves-1].from = move.from;
198: Move_history[Number_half_moves-1].to = move.to;
$