Saturday, 11 August 2007

Vi Search and Replace

Sometimes when working with Linux cli, you have to edit files and make bulk changes to configuration files.

I use vi as a text editor and I thought I'd add this example fo search and replace using vi;

:1,$s/sometexttoreplace/newtext

In the above example, 1 represents the first line, $s represents the end line.

One important thing to note is that you need to escape any characters like dots, for example;

:1,$s/suffolkweb-design\.co\.uk/suffolk-web-design\.com

would be the way you change domain names from suffolk-web-design.co.uk to suffolk-web-design.com

No comments: