Logo Background

Search & Replace Using Vi

  • By on October 11, 2008 | 2 Comments

    In the event of word substitution, you might want to perform search and replace in 1 files of certain words and replace it with the desired words. Here’s the command that you can enter in Vi mode.

    Vi> :%s///g

    Example: – You might want to search and replace the word “bad” to “good” in the file. The substitution of the command will be like this: –

    Vi> :%s/bad/good/g

    Some description of the command, %s will perform the search on the word “bad” and replace it with the word “good” and “g” represents global parameter which means the substitution will be on the entire file.

    In the coming topic, I will share more on how to perform the search and replace in all the files without opening the files via Vi command using advance shell programming.

    Previous
    Next
    » Unzip Several Zip Files
  1. #1 giraffe
    October 11, 2008 8:54 pm

    yah, this is useful especially when you have ftp files which contained ^M at the back of each line … you may vi your file and use :%s/.$//

    Post ReplyPost Reply
  1. #2 zenux
    October 11, 2008 9:02 pm

    The :%s/.$// work just great, now I can filter those special character with ^M

    Post ReplyPost Reply
Leave a Comment