分类: LINUX
2008-03-13 18:56:46
以下是使用的源文件。
% 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
需要将名字tom替换为Tom,在vi中使用如下的命令。可以看到确实实现了替换,但是anatomy也会被替换为anaTomy。
正确的替换方法是对单词进行替换。
1,$s/\
另外一下是对RE元字符的介绍:
^Beginning−of−line
anchor/^love/Matches all lines beginning with love.$End−of−line anchor/love$/Matches
all lines ending with love..Matches one character/l..e/Matches lines containing
an l, followed by two characters, followed by an e.*Matches zero or more of the
preceding characters/ *love/Match lines with zero or more spaces, followed by
the pattern love.[ ]Matches one in the set/[Ll]ove/Matches lines containing
love or Love.[x–y]Matches one character within a range in the
set/[A–Z]ove/Matches letters from A through Z followed by ove.[^ ]Matches one
character not in the set /[^A–Z]/ Matches any character not in the range
between A and Z.\Used to escape a Metacharacter /love\./ Matches lines
containing love, followed by a literal period. Normally the period matches one
of any character. Additional metacharacters are supported by many UNIX programs
that use RE
metacharacters:\