Chinaunix首页 | 论坛 | 博客
  • 博客访问: 203144
  • 博文数量: 73
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 750
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 18:32
文章分类

全部博文(73)

文章存档

2009年(1)

2008年(72)

我的朋友

分类: 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中使用如下的命令。
1,$s/tom/Tom/g

可以看到确实实现了替换,但是anatomy也会被替换为anaTomy。

正确的替换方法是对单词进行替换。

1,$s/\/Tom/g这样就不会出现以上的错误。

另外一下是对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:\End−of−word anchor/love\>/Matches lines containing a word that ends with love(supported by vi and grep).\(..\)Tags match characters to be used later /\(love\)able \1er/May use up to nine tags, starting with the first tag at the left−most part of the pattern. For example, the pattern love is saved as tag 1, to be referenced later as \1; in this example, the search pattern consists of lovable followed by lovesupported by sed, vi, and grep).x{m\}or x{m,\}or x{m,n\}Repetition of character x, m times, at least m times,at least m and not more than n times[a]o{5,10\}Matches if line contains between 5 and 10 consecutive occurrences of the letter o (supported by vi and grep).Assuming that you know how the vi editor works, each metacharacter is described in terms of the vi search string. In the following examples, characters are highlighted to demonstrate what vi will find in its search.


阅读(1128) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:强大的grep家族

给主人留下些什么吧!~~