|
发表于 2008-1-24 21:18:27
|
显示全部楼层
Post by mascot;1810782
一个文件 “file” 的内容如下:
This is a test.
Yahoooooooooo
将文件所有行前面加上空格,很简单:
# sed 's/^/ /' file
This is a test.
Yahoooooooooo
我想在每一行前面加五个空格,我这么用的:
# sed 's/^/ \{5\}/' file
{5}This is a test.
{5}Yahoooooooooo
看来这种倍数的用法无效,我不知道是为什么,而这种倍数用法在下面的模式匹配是行得通的:
# sed -n '/o\{5\}/p' file
Yahoooooooooo
所以,得出结论,这种倍数用法不适用于替换,觉得不应该是这样的结果,不知道为什么。我的问题是,在替换的时候,如何表达倍数?
哈哈,当年我也困惑过。都怪自己没理解人家的意思。
其实,sed的语法是s/regular-expression/replacement text/
而\{\}是regular-expression, 不能用在replacement text |
|