RSS

Global search and replace using Vi

Fri, Apr 28, 2006

System Administration

to replace all instances of - say - 127.0.0.1 with 10.0.0.1 in a file then using vi you can do:

[code]:%s/127\.0\.0\.1/10\.0\.0\.1/g[/code]

if you mess it up then press u for undo. Of course if it’s an important file then back it up first.

This post was written by:

Bealers - who has written 350 posts on Darren Beale.


Contact the author

3 Comments For This Post

  1. Mike Says:

    Do you think maybe you could have used a simpler example without all of the escapes for the .’s ? how about this? Replace all instances of overcomplicated in a file:

    %s/overcomplicated/simple/g

  2. Bealers Says:

    *shrug* I was simply illustrating the task that I was doing at that moment.

  3. Carlos Says:

    Your example is actually a good one. The fact is that a very common use for global search/replace in vii is to replace ip addresses in .conf files. This example perfectly illustrates doing just that, and is unlikely to confuse anyone with even some experience with posix type os.

Leave a Reply