3

I would like to know if is possible in vi to add at the end of a line some specific character of ther line itself. Example: Before

    donald /mount/donald_01
    mickey /mount/mickey_01
    mickeym /mount/mickey_02

After some :%s%"last two characters"%"last two characters"/"last two characters"% command

    donald /mount/donald_01/01
    mickey /mount/mickey_01/01
    mickeym /mount/mickey_02/02

Thanks gb

gogolb
  • 97

1 Answers1

7

I don't know about vi, so that might not be useful, but in VIM you can do something like that:

donald /mount/donald_01
mickey /mount/mickey_01
mickeym /mount/mickey_02

%s%\(..\)$%\1/\1% will give you the following output:

donald /mount/donald_01/01
mickey /mount/mickey_01/01
mickeym /mount/mickey_02/02

The syntax is very close to that of sed. You might want to learn this.

EDIT: I just got to work and tried it with an old vi version. It works.

rahmu
  • 20,023