分类: LINUX
2008-03-13 19:35:58
% vi letter
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Hi tom,
I think I failed my anatomy test
yesterday. I had a terrible
stomach ache. I ate too many fried green
tomatoes.
Anyway, Tom, I need your help. I'd like
to make the test up
tomorrow, but don't know where to begin
studying. Do you
think you could help me? After work,
about 7 PM, come to
my place and I'll treat you to pizza in
return for your help. Thanks.
Your pal,
guy@phantom
在/etc/passwd查找一个不存在的用户。 grep ' ' /etc/passwd echo $?(返回的状态量保存在$?变量中) 另外在c shell中还会将该变量保存在status变量中。 |
% cat datafile
northwest
NW Charles Main 3.0 .98 3 34
western WE
Sharon Gray 5.3 .97 5 23
southwest
SW Lewis Dalsass 2.7 .8 2 18
southern
SO Suan Chin 5.1 .95 4 15
southeast
SE Patricia Hemenway 4.0 .7 4 17
eastern EA
TB Savage 4.4 .84 5 20
northeast
NE AM Main Jr. 5.1 .94 3 13
north NO Margot Weber 4.5 .89 5 9
central CT Ann Stephens 5.7 .94 5 13
#比较一下两行代码的不同: grep NW datafile grep NW d* |
#The importance of being quoted: grep TB Savage datafile grep 'TB Savage' datafile |
#?单词,grep对单词的理解,单词可以包含空格。 grep '\<[a-z].*n\>' datafile #The output is: northwest NW Charles Main 3.0 .98 3 34 |
5,与管道符一起使用
#打印当前目录下的所有子目录。
#打印目录下所有匹配模式的文件名 grep -l 'NW' * #打印匹配的行数 grep -c '^northwest' datafile #打印不匹配的航 grep -v 'TB Savage' datafile |