- 论坛徽章:
- 0
|
在原版的《linux shell s by example》中
$s/\([0o]ccur\)ence/\1rence/
解释:The editor searches for the entire string occurence or Occurence (note: the words are misspelled), and if found, the pattern portion enclosed in parentheses is tagged (i.e., either occur or Occur is tagged). Since this is the first pattern tagged, it is called tag 1. The pattern is stored in a memory register called register 1. On the replacement side, the contents of the register are replaced for \1 and the rest of the word rence, is appended to it. We started with "occurence" and ended up with "occurrence."
说是标签1中被保存在寄存器1中,把\1中的内容替换,occurence开始,以occurrence结束,谁能详细解释下各部分的用法?
还有这个
s/\(square\) and \(fair\)/\2 and \1/
标签2的寄存器存了fair,标签1寄存器存了square,\2为fair,\1为fair,匹配square and fair,不知道这样了解是否对? |
|