Linux : Search and replace across multiple files

By | November 9, 2011

To search and replace across multiple text file on a Linux/Unix system, use the following command :

find . -name "*.extension" -print | xargs sed -i 's/search_for_text/replace_with_text/g'

So, as example, let’s assume you want to replace an IP address in multiple Bind zone file (using the extension .hosts) and replace IP address 10.10.1.1 for 192.168.1.1 :

find . -name "*.hosts" -print | xargs sed -i 's/10.10.1.1/192.168.1.1/g'