Unix Grep

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;
$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值