Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.