Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: vi editor ^v^m lost special meaning

  1. #1
    Join Date
    Apr 2012
    Beans
    11

    vi editor ^v^m lost special meaning

    I am looking for something that doesnt lose its special function when writing a script. I am trying to use vi editor to change many files and cannot find any solution.

    :g/G53G28G49Z-\.25/s//G90G53G49Z0%0d G91G28Z0/g
    or
    :g/G53G28G49Z-\.25/s//G90G53G49Z0^v^m G91G28Z0/g

    I have tried these without success, as you can see I am trying to get a ctrl-v ctrl-m . these both work when typed into vi , but when passed from elsewhere or even cut and pasted it loses its original function.

    any ideas, or another solution ?

  2. #2
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: vi editor ^v^m lost special meaning

    What exactly are you trying to achieve by using vi?

    You can use the sed or awk commands to achieve everything that I can think of that you would use vi for.
    Cheesemill

  3. #3
    Join Date
    Apr 2012
    Beans
    11

    Re: vi editor ^v^m lost special meaning

    I am just more familiar with vi. I was assuming that I may have the same issue with those tho. what would the command for those look like?

  4. #4
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: vi editor ^v^m lost special meaning

    Quote Originally Posted by uuuuserrrr View Post
    I am just more familiar with vi. I was assuming that I may have the same issue with those tho. what would the command for those look like?
    Again, that depends.

    What exactly are you trying to achieve using vi?
    Cheesemill

  5. #5
    Join Date
    Apr 2012
    Beans
    11

    Re: vi editor ^v^m lost special meaning

    I am trying to replace a string of characters with another string of characters and another line of characters on about 500 files.

  6. #6
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: vi editor ^v^m lost special meaning

    Vi isn't meant to be used in scripts, only interactively. The preferred method in this situation would be to use sed.

    To do a find and replace with sed you would use:
    Code:
    sed -i 's/searchterm/replacement/g' filename.txt
    This will replace all occurrences of searchterm with replacement in the file filename.txt

    You can add the find command to do this over multiple files at the same time, for example to do a find and replace in every file in a directory you could do:
    Code:
    find /home/user/directory -type f -exec sed -i 's/searchterm/replacement/g' {} \;
    Last edited by Cheesemill; November 13th, 2012 at 09:37 PM.
    Cheesemill

  7. #7
    Join Date
    Dec 2010
    Location
    IR, Teh
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Smile Re: vi editor ^v^m lost special meaning

    Are you wanna to find a string? I known your mean as well?
    Try with this command in terminal :
    Code:
     grep -i "string" files.*
    Last edited by smss; November 13th, 2012 at 09:47 PM.

  8. #8
    Join Date
    Apr 2012
    Beans
    11

    Re: vi editor ^v^m lost special meaning

    thanks
    i will try tomorrow, maybe the ctrl functions wont be lost there

  9. #9
    Join Date
    Apr 2012
    Beans
    7,256

    Re: vi editor ^v^m lost special meaning

    If you're trying to replace DOS-style line terminations then in 'sed' it's probably less ambiguous to use the escape character \r rather than using the Ctrl-v Ctrl-m control sequence (since ^M could be read as an anchored literal M)

    Code:
    $ sed -i 's/\r$//'

  10. #10
    Join Date
    Apr 2012
    Beans
    11

    Re: vi editor ^v^m lost special meaning

    i cannot try that right now, as i am not near a computer now, but i will try further to clairify what i am trying to do.

    i need to replace a string and add a additional line after.

    example
    original: fo fo fo [search string]

    desired: fo fo fo [replace string]
    [additional line of replace string]

    my issue is that the ^v^m is coming over literaly when using it, other than in the command line

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •