| 1 | #print |
| 2 | So far all the special characters in the substitute command |
| 3 | have been used in the left-hand expression, the one that |
| 4 | is looked for in the line as it exists before the change. |
| 5 | None of these characters are meaningful in the right-hand |
| 6 | expression; for example, |
| 7 | s/ab/a./ |
| 8 | turn "ab" into "a." just as if "." were an ordinary letter. |
| 9 | But there is one character that is special on the right |
| 10 | side of a substitution, which is '&'. The ampersand |
| 11 | is replaced by whatever text is being replaced. In |
| 12 | s/the/&m/ |
| 13 | the string "the" is turned into "them" because the '&' is |
| 14 | replaced by "the". |
| 15 | In this directory there is a file 'text'; on the third line, |
| 16 | change the word 'dog' into 'dogs'; then rewrite the file |
| 17 | and say "ready". |
| 18 | #create Ref |
| 19 | cat |
| 20 | mouse |
| 21 | dogs |
| 22 | rat |
| 23 | #create text |
| 24 | cat |
| 25 | mouse |
| 26 | dog |
| 27 | rat |
| 28 | #user |
| 29 | #cmp text Ref |
| 30 | #log |
| 31 | #next |
| 32 | 37.1a 10 |
| 33 | 37.2a 6 |